Sort data so that my exact match will be on top and then semi exact match with most words snd so on

I am using query_string for searching my data. and wanted to sort my data such that exact match should be on top and less matched words would follow exact match.
For Instance,

{
  "size": 100,
  //"explain":true,
  "query": {
    "bool": {
          "should": [
            {
              "query_string": {
            "query": "*increased blood glucose levels* OR *increased* OR *blood* OR *glucose* OR *levels*",
                "fields": ["search_key^1", "dis_name^2", "dis_info.description^1"]
              }
            },
            {
              "query_string": {
                "query": "\"increased blood glucose levels\"",
                "fields": ["search_key.keyword^2", "dis_name.keyword^5", "dis_info.description.keyword^2"],
                "boost":100
              }
            },
            {
              "query_string": {
                "query": "\"increased blood\" OR \"increased glucose\" OR \"increased levels\" OR \"blood glucose\" OR \"blood levels\" OR \"glucose levels\" OR \"increased blood glucose\" OR \"increased blood levels\" OR \"increased glucose levels\" OR \"blood glucose levels\"",
                "fields": ["search_key.keyword^2", "dis_name.keyword^5", "dis_info.description.keyword^2"],
                "boost":50
              }
            }
          ]
        }
  }
}

As you can see, I boosted exact match query, But for semi phrase I finding all the combinations and boosting it. Problem is if i have many words than combinations can increase exponentially.

Is there any other solution for the same?

First, the above query my return different results than you expect. As long as there is no must or filter or must_not part in your boolean query, the should clauses will be combined with an OR and will not be about boosting.

Second, can you explain to me what the original user typed query looked like in this example? Just to make sure I understand the way of processing.

Thanks!

I am getting perfect data but in different order, I want order to be like ->
For instance If user search "increased blood glucose" than results should be
-> increased blood glucose (exact match)
-> increased blood ( all the combinations of the words in that document with max words should be on top)
-> blood glucose (same as above)

-> humanblood (wildcard results as blood matchs -> here same if more number of word matches than that data should be on top than other)

1 Like

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.