Combine phrase with boost in Query String Query

Is it possible to combine phrase with boost in Query String Query?

description:“continental breakfast”^2

If it is not possible what are alternatives? Would boost work with Phrase Query or Match Phrase Query?
Background: I am searching for a non-exact person name and want to boost last name match over first name match for multi-word names like ‘Jean Claude’ ‘Van Damme’ .
Thank you.

Yes I believe it should work.
Boost is supported for phrase and match phrase queries - essentially all kinds of queries.

Here’re some examples …

  • Query string query (alternative representation)

    {"query":  {"query": "description:'continental breakfast'", "boost": 2}}`
  • Phrase query (if order doesn’t matter)

    {"query":  {"field": "description", "terms": ["continental",  "breakfast"], "boost": 2}}`
  • Match query (if order doesn’t matter)

    {"query":  {"field": "description", "match": "continental breakfast", "operator": 1, "boost": 2}}`
  • Match Phrase query (if order matters) (Note that the field needs to be indexed with “include term vectors” for this)

    {"query":  {"field": "description", "match_phrase": "continental breakfast", "boost": 2}}`

I read “show scoring” for Query String Query

description:“continental breakfast”^2

against demo travel-sample-index-hotel-description in admin Ui and boost is always "1.000 - boost ". I believe it is the same when calling Query String Query from SDK based on scoring numbers.

Good observation. It seems like we don’t support boosting when the search term is enclosed within "" - so query string queries won’t support boosting over phrases - apologies on that.

My advise here for you is to use the alternatives - match_phrase/phrase or run a query string query (not from the UI, so you can explicitly set the boost) via REST APIs/Curl Requests/SDK.

A possible way around here. Enclosing search phrase in single quotations does include some boost into scoring.

description:‘continental breakfast’^2

Please confirm

No - single quotes can’t be an option.

Single quotes are treated as any other character in query strings (not a special character). So in your example: 'continental is looked for within the field description and breakfast' with a boost of 2 is looked for within the composite field: _all

Got it. Thank you! :smile: