Query string with promotion fields in Elastic Search

I am using Query String

with Boost Fields

in Elastic Search 1.7

. It works fine, but in some scenario I am not getting the expected result.
Query:

query
{
   "from": 0,
   "size": 10,
   "explain": true,
   "query": {
      "function_score": {
         "query": {
            "query_string": {
               "query": "account and data",
               "fields": [
                  "title^5"
                  "authors^4",
                  "year^5",
                  "topic^6"
               ],
               "default_operator": "and",
               "analyze_wildcard": true
            }
         },
         "score_mode": "sum",
         "boost_mode": "sum",
         "max_boost": 100
      }
   }
}

      

Sample data

{
   "took": 50,
   "timed_out": false,
   "_shards": {
      "total": 5,
      "successful": 5,
      "failed": 0
   },
   "hits": {
      "total": 4,
      "max_score": 12.833213,
      "hits": [
         {
            "_id": "19850",
            "_score": 12.833213,
            "_source": {
               "ID": "19850",
               "Year": "2010",
               "Title": "account and data :..."
            }
         },
         {
            "_id": "16896",
            "_score": 11.867042,
            "_source": {
               "ID": "16896",
               "Year": "2014",
               "Title": "effectivness of data..."
            }
         },
         {
            "_id": "59862",
            "_score": 9.706333,
            "_source": {
               "ID": "59862",
               "Year": "2007",
               "Title": "best system to..."
            }
         },
         {
            "_id": "18501",
            "_score": 9.685843,
            "_source": {
               "ID": "18501",
               "Year": "2010",
               "Title": "management of..."
            }
         }
      ]
}

      

I am getting above the sample data using a query and it is as expected. But now if I increase weight

from year

to 100, then I expect 4th result at 3rd position and 3rd result at 4th position. I've tried many things, but I don't know what I am doing wrong.

+3


source to share


1 answer


Gain is only used when the query matches the field you are incrementing, and it multiplies the elastic search results that you define. In your query, you are looking for "account and data"

and this does not match any year, so a year boost will not be used.

Are you trying to account for the year for an order? If so, you can try adding field_value_factor

to your request like this:

"query" : {
    "function_score": {
        "query": { <your query goes here> },
        "field_value_factor": {
            "field": "year"
         }
    }
}

      



This will multiply the year with the calculation of elastic results, so it takes into account the year without having to order by year. You can read about it here https://www.elastic.co/guide/en/elasticsearch/guide/current/boosting-by-popularity.html .

You can always use the annotation tool to figure out how elastic a search came up with and thus returned results in that order. https://www.elastic.co/guide/en/elasticsearch/reference/current/search-explain.html

+4


source







All Articles