0

Having the following query:

curl -XGET 'localhost/my_index/my_type/_search?pretty=true' -d'
{
"query": {
  "bool": {
     "must": [
        {
           "query_string": {
              "default_field": "body",
              "query": "hello stackoverflow"
           }
        },
        {
           "terms": {
              "_id": ["10"]
           }
        },
        {
           "has_child": {
              "type": "user_item_relation",
              "query": {
                 "term": {
                    "user_id": "1234"
        }}}},
        {
           "has_child": {
              "type": "user_item_relation",
              "query": {
                 "term": {
                    "fav": "0"
}}}}]}}}'

Is there a way to combine the two last conditions (user_id = 1234 and fav = "0") on a single one without using two times has_child?

1 Answer 1

1

Use bool query inside has_child.

curl -XGET "http://localhost:9200/my_index/my_type/_search?pretty=true" -d'
{
"query": {
  "bool": {
     "must": [
        {
           "query_string": {
              "default_field": "body",
              "query": "hello stackoverflow"
           }
        },
        {
           "terms": {
              "_id": [
                 "10"
              ]
           }
        },
        {
           "has_child": {
              "type": "user_item_relation",
              "query": {
                 "bool": {
                    "must": [
                       {
                          "term": {
                             "user_id": "1234"
                          }
                       },
                       {
                          "term": {
                             "fav": "0"
                          }
                       }
                    ]
                 }
              }
           }
        }
     ]
    }
  }
 }'
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.