2

I'm wondering if there is a possibility to combine two query types, in my case I need a match and wildcard query, each has to operate on a different field.

The thing is, a document matches if the entity name (the document is the representation of the entity) matches the name with a wildcard at the end of the search term OR it matches if it is a exact match on one of the synonyms of the entity. Not both querys have to match, just one of them to consider the document as relevant.

Currently I need two requests to archive this:

Wildcard:

GET /name/type/_search
{
   "query": {
      "wildcard": {
         "name": {
            "value": "term*",
            "boost": 2
         }
      }
   }
}

Match:

GET /name/type/_search
{
   "query": {
      "match": {
         "synonyms": "term"
      }
   }
}

Is there a way to do it with one request? All my tests failed.

4
  • Have a look at the bool query SO Answer Commented Apr 15, 2014 at 14:15
  • With the bool query both queries have to match, in my case one of them have to match in order to consider the document as valid hit. I updated the question to point this out. Thx. Commented Apr 15, 2014 at 15:00
  • 2
    Then use should instead of must. See the docs. Commented Apr 15, 2014 at 15:08
  • I was kind of lost in the docs, I SHOULD read more carefully. Thank you, thats what I was looking for. Commented Apr 15, 2014 at 15:45

1 Answer 1

4

This is the one your are looking for..!

curl -XPOST "http://localhost:9200/try/_search" -d'
{
  "query": {
    "bool": {
      "should": [
        {
          "wildcard": {
            "name": {
              "value": "term*",
              "boost": 2
            }
          }
        },
        {
          "match": {
            "synonyms": "term"
          }
        }
      ]
    }
  }
}'
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.