Проблема запроса DSL эластичного поиска, есть поле вложенного типа Person в индексе, Person имеет поле Country, Person в индексе вставляет две данные, вам нужно запросить Country = A первой строки и Country = B второго ряда.
Структура индексной таблицы:
http://127.0.0.1:9200/event
PUT
{
"mappings": {
"event": {
"properties": {
"Quantity": {
"type": "integer"
},
"Person": {
"type": "nested",
"properties": {
"CountryCode": {
"type": "text",
"fields": {
"keyword": {
"ignore_above": 256,
"type": "keyword"
}
}
}
}
}
}
}
}
}
Вставить данные:
{"Quantity":10,"Person":[{"CountryCode":"A"},{"CountryCode":"B"}]}
{"Quantity":5,"Person":[{"CountryCode":"B"},{"CountryCode":"A"}]}
{"Quantity":3,"Person":[{"CountryCode":"A"},{"CountryCode":"C"}]}
{"Quantity":7,"Person":[{"CountryCode":"D"},{"CountryCode":"E"}]}
В результате запроса, в результате этого оператора невозможно определить Country = A в первой строке, Country = B во второй строке:
http://127.0.0.1:9200/event/event/_search
POST
{
"query": {
"bool": {
"must": [
{
"nested": {
"path": "Person",
"query": {
"bool": {
"must": {
"match": {
"Person.CountryCode.keyword": "A"
}
}
}
}
}
},
{
"nested": {
"path": "Person",
"query": {
"bool": {
"must": {
"match": {
"Person.CountryCode.keyword": "B"
}
}
}
}
}
}
]
}
}
}
{
"took": 10,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"skipped": 0,
"failed": 0
},
"hits": {
"total": 2,
"max_score": 2.4079456,
"hits": [
{
"_index": "event",
"_type": "event",
"_id": "2",
"_score": 2.4079456,
"_source": {
"Quantity": 5,
"Person": [
{
"CountryCode": "B"
},
{
"CountryCode": "A"
}
]
}
},
{
"_index": "event",
"_type": "event",
"_id": "1",
"_score": 1.3862944,
"_source": {
"Quantity": 10,
"Person": [
{
"CountryCode": "A"
},
{
"CountryCode": "B"
}
]
}
}
]
}
}