1

I have Elasticsearch documents look like:

Doc 1:
{
  "name" : "Tom",
  "values" : [
    { "value" : "value 1" },
    { "value" : "value 2" },
    { "value" : "value 3" }
  ]
}

Doc 2:
{
  "name" : "Bob",
  "values" : [
    { "value" : "value 1" },
    { "value" : "value 2" }
  ]
}

How can I query by docs which the values array size is larger than 2?

1

1 Answer 1

1

You need to add this to your bool query.

"filter" : {
    "script" : {
        "script" : "doc['values'].values.size() > 2"
    }
}

filter filters the document which matches the condition.

size() returns the size of the array.

doc['values'] looks for values field.

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.