Prioritize exact words first and then others while using query_string query in elasticsearch

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Prioritize exact words first and then others while using query_string query in elasticsearch

jugal
This post has NOT been accepted by the mailing list yet.
If I search for a term "Liebe" the current query and the analyzers used, returns me the results containing the word "Liebe" as a part of a different word "Verlieben" are prioritized over those with only this word. It should be the other way. I am also using some advance filters and aggregations too. But here is the most basic query that I use to search.
{
  "query": {
    "query_string": {
        "query": "Liebe",
        "default_operator": "AND",
        "analyzer": "my_analyzer1"
    }
  },
  "size": "10",
  "from": 0
}
The analyzers and index settings are as follows:
{
       "settings": {
          "analysis": {
             "filter": {
                "nGram_filter": {
                   "type": "nGram",
                   "min_gram": 2,
                   "max_gram": 20,
                   "token_chars": [
                      "letter",
                      "digit",
                      "punctuation",
                      "symbol"
                   ]
                }
             },
             "analyzer": {
                "nGram_analyzer": {
                   "type": "custom",
                   "tokenizer": "whitespace",
                   "filter": [
                      "lowercase",
                      "asciifolding",
                      "nGram_filter"
                   ]
                },
                "whitespace_analyzer": {
                   "type": "custom",
                   "tokenizer": "whitespace",
                   "filter": [
                      "lowercase",
                      "asciifolding"
                   ]
                },
                "my_analyzer1":{
                        "type": "custom",
                        "tokenizer": "whitespace",
                        "filter": [
                          "lowercase",
                          "my_stop'.$s_id.'",
                          "asciifolding"
                        ]
                    }
             }
          }
       },
       "mappings": {
          "product": {
             "_all": {
                "index_analyzer": "nGram_analyzer",
                "search_analyzer": "whitespace_analyzer"
             },
             "properties": {
                '.$mapping.'
             }
          }
       }
    }
Please ignore the $mapping. These are the dynamic fields that reside in the index based on some settings in my framework. Can anyone please point me some direction where I don't need to change more and can get the what I mentioned above? I have checked many things like match query n all. But, I don't have any fields fixed. So,I cant use that. And I want both the exact search and the search results which has partial match(Using nGrams). Please help! Thanks!