1

The example is extracted from Elasticsearch reference: https://www.elastic.co/guide/en/elasticsearch/reference/5.3/nested.html

My index is similar to this. The only difference is user.first and user.last are keyword type so I can use filter on them.

PUT my_index
{
  "mappings": {
    "my_type": {
      "properties": {
        "user": {
          "type": "nested" 
        }
      }
    }
  }
}

PUT my_index/my_type/1
{
  "group" : "fans",
  "user" : [
    {
      "first" : "John",
      "last" :  "Smith"
    },
    {
      "first" : "Alice",
      "last" :  "White"
    }
  ]
}

What is the query I should use to get documents that match the above array (exactly two items, one item is John Smith, one item is Alice White) in two situations:

  1. Order doesn't matter
  2. Order matters

1 Answer 1

0

After searching, the best way to achieve Order doesn't matter is: indexing a Count field.

See: Elasticsearch Equal Exactly

The reason is:

In Elasticsearch, there is no dedicated array type. Any field can contain zero or more values by default, however, all values in the array must be of the same datatype.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.