shuvomiah
shuvomiah

Reputation: 410

ElasticSearch string query prefer exact to wildcard

I have 2 entries

  1. Rahim
  2. Rahima

When I search "Rahim" with query_string with wildcard, I got 2 entires with same score. But as "Rahim" matches exactly, it will be great for me to have "Rahim" first with higher score, and "Rahima" later with lower score. The query is:

GET index/type/_search
{
  "query": {
    "query_string": {
      "default_field": "fullNameEn",
      "allow_leading_wildcard": false,
      "analyze_wildcard": true,
      "query": "Rahim*"
    }
  },
  "from": 0,
  "size": 10
}

Any help will be appreciated.

Upvotes: 1

Views: 397

Answers (1)

astax
astax

Reputation: 1767

Use terms boosting in query string

GET index/type/_search
{
  "query": {
    "query_string": {
      "default_field": "fullNameEn",
      "allow_leading_wildcard": false,
      "analyze_wildcard": true,
      "query": "Rahim^2 OR Rahim*"
    }
  },
  "from": 0,
  "size": 10
}

Upvotes: 2

Related Questions