Phil B
Phil B

Reputation: 6037

Elasticsearch boost a field when using query_string

Is it possible to boost a field in a query of this form?

   "query": {
      "filtered": {
         "query": {
            "query_string": {
               "query": "the user's search query",
               "fields": ["name", "description"],
               "default_operator": "OR"
            }
         },
         "filter": {...}
      }
   }

Upvotes: 7

Views: 6050

Answers (1)

ppearcy
ppearcy

Reputation: 2762

Yes, just add the boost syntax on the field (name^5), eg:

"query": {
   "filtered": {
      "query": {
         "query_string": {
            "query": "the user's search query",
            "fields": ["name^5", "description"],
            "default_operator": "OR"
         }
      },
      "filter": {...}
   }
}

Seems pretty clear in the docs: https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-query-string-query.html#_boosting

Upvotes: 20

Related Questions