0

I wanted to query Elastic Search with the condition that the documents should contain the pair of values.

I have a pair of values, how can we query the elastic search with the pair.

Example: This is the indexed data

{
  "messageId": "abc",
  "Identifiers": {
    "foo": "val1",
    "bar": "val2"
  },
  "labels": {
    "label1": "value1",
    "label2": "value2"
  }
}

I would like to retrieve the documents that matches the given pair of values.

For example if my pair is pair(val1, val2) then, when we query the ES with the pair(val1, val2) we should get the document with messageId "abc"

1 Answer 1

1

I believe that Bool Query with Must clausule would be an option.

{
  "query": {
    "bool": {
      "must": [
        {
          "match": {
            "Identifiers.foo": {
              "query": "val1"
            }
          }
        },
        {
          "match": {
            "Identifiers.bar": {
              "query": "val2"
            }
          }
        }
      ]
    }
  }
}
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.