I am using elasticsearch-6.4.3
I have created an index test_index with the following mapping:
PUT test_index
{
"mappings": {
"_doc": {
"properties": {
"name": {
"type": "keyword"
},
"segments": {
"type": "nested",
"properties": {
"f1": {
"type": "keyword"
},
"f2": {
"type": "integer"
}
}
}
}
}
}
}
I inserted a document in the index with the following command:
POST /test_index/_doc
{
"name": "ABC",
"segments": [{
"f1": "abc",
"f2": 123
},
{
"f1": "def",
"f2": 124
}]
}
I have an array of values say arr = ["def", "xyz"]. I want to match all the documents whose atleast one of the f1 field in segments field match with any of the values in the given array arr.
You can call it something like array_intersect to easier to understand.
I am trying something like this:
GET /test_index/_search
{
"query": {
"nested": {
"path": "segments",
"query": {
"bool": {
"must": [
{
"terms": {
"f1": [
"def",
"xyz"
]
}
}
]
}
}
}
}
}
I am getting no results as the output.
Expected output: The document should match as "def" is present as value of f1 in the document.