Запрос выглядит так:
GET countries/_search
{
"query": {
"bool": {
"must": [
{
"term": {
"data.attributes.country.keyword":{
"value": "india"
}
}
}
],
"must_not": [
{
"term": {
"data.attributes.country":{
"value": "usa"
}
}
}
]
}
}
}
Ответ:
{
"took" : 2,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 2,
"relation" : "eq"
},
"max_score" : 0.16786805,
"hits" : [
{
"_index" : "countries",
"_type" : "_doc",
"_id" : "3",
"_score" : 0.16786805,
"_source" : {
"data" : {
"attributes" : {
"name" : "test",
"country" : [
"india"
]
}
}
}
},
{
"_index" : "countries",
"_type" : "_doc",
"_id" : "2",
"_score" : 0.13353139,
"_source" : {
"data" : {
"attributes" : {
"name" : "test",
"country" : [
"india",
"japan"
]
}
}
}
}
]
}
}
Шаги для воспроизведения:
PUT countries
PUT countries/_doc/1
{
"data": {
"attributes": {
"name": "test",
"country": [
"india",
"usa",
"japan"
]
}
}
}
PUT countries/_doc/2
{
"data": {
"attributes": {
"name": "test",
"country": [
"india",
"japan"
]
}
}
}
PUT countries/_doc/3
{
"data": {
"attributes": {
"name": "test",
"country": [
"india"
]
}
}
}