How to match exactly one item in an array

Hi guys

I have a question when matching a field with array.

Here is my data:

Item1:

{
 "names": ["foo-123-sth-more", "bar-456-sth-more"]
}

Item2:

{
 "names": ["foo-456-sth-more", "bar-123-sth-more"]
}

My query is

{
    "query": {
        "match" : {
            "names" : {
                "query" : "foo 456",
                "operator" : "and"
            }
        }
    }
}

Both item1 and item2 will matched, but the expected result is only item2 match, every element in array should be consider as an independent text to handle.

Is there any one could tell me how to handle this case? thank you.

You should use nested datatypes. It is just the way arrays are indexed that shows the behaviour are you noticing.
Check this out - https://www.elastic.co/guide/en/elasticsearch/reference/current/nested.html

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.