0
votes

How to create keywords based search using ElasticSearch where exact phrase match should be shown in the top of the result set followed by other match containing any words of the phrase.

For an example of search query is quick brown fox and result set will be like : quick brown fox, quick fox, brown fox etc.

What should be the approach so we get desire result set.

1

1 Answers

0
votes

Try with 'query_string' :-

Raw Data :-

1) quick brown fox
2) quick fox
3) brown fox

QUERY :-

{ 

  "query": {
    "query_string": {
       "fields" : ["fieldName"] ,
      "query": "*quick*  *brown* *fox*"
    }
  }
}

Response will be :-

1)quick brown fox 
2)brown fox
3)quick fox

I think query_string is doing right job .We have three token (quick , brown ,fox ) . Query_string prefers "brown fox" than "quick fox" because it will give priority to combined token than separated token .