0

have 4 different results in such kind of queries:

GET _search
{
  "query": {
    "query_string": {
      "default_field": "desc",
      "query": "лес"
    }
  }
}
GET _search
{
  "query": {
    "query_string": {
      "default_field": "desc",
      "query": "лес*"
    }
  }
}
GET _search
{
  "query": {
    "query_string": {
      "default_field": "desc",
      "query": "*лес"
    }
  }
}
GET _search
{
  "query": {
    "query_string": {
      "default_field": "desc",
      "query": "*лес*"
    }
  }
}

The difference is the asterisk position. Is it possible to get results from all four queries in one ?

1 Answer 1

2

if you don't need to differentiate what query has determined a successful hit, then you can just use a boolean should query. Something like

{
  "query": {
    "bool": {
      "should": [
      {
        "query_string": {
          "default_field": "desc",
          "query": "лес"
        }
      },
      {
        "query_string": {
          "default_field": "desc",
          "query": "лес*"
        }
      },
      ... 
      ]
    }
  }
}

Update with some recommendations on the queries:

  • I'm not sure what you need *nec, nec*, and *nec* for. If you are going to combine them, and you don't need to differentiate the hit match, isn't *nec* enough?
  • I would recommend you switching from match_query to match (first query), prefix and wildcard (on the other queries, if you have non-analysed sub-fields available)
Sign up to request clarification or add additional context in comments.

5 Comments

pastebin.com/xw4CPeA1 constructed query. It's always same result (from query without asterisk). Even in reversed query order.
Didn't get the right result from bool. So i made 4 different requests and merged results. That's a heavy payload. But i don't know any other way at this time.
Do you get the expected results when you query using wildcards? I'm going to update my answer with some recommendations on the single queries
In my case *nec* and *nec are different in results. I thought that *nec* is a summ pattern for *nec and nec* but really it's not.
Solved. The default "from" : 0, "size" : 10, need to be extended cause i have more than 100 hits in *nec*.

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.