c# - Elastic Search Boost Query - Stack Overflow

admin2025-04-17  2

I have query like this:

{
  "query": {
    "bool": {
      "must": [
        {
          "term": {
            "IsDeleted": {
              "value": false
            }
          }
        },
        {
          "query_string": {
            "fields": [
              "FirstName^10",
              "LastName^10",
              "CompanyName^5",
              "MobilePhone^3",
              "MobilePhone^4",
              "ContactName^3",
              "CompanyName^3",
              "ContactMobilePhoneSearch^2",
              "CompanyName^2",
            ],
            "query": "/محمد(.*?)/ AND /محمد(ی|ي|ئ)(.*?)/"
          }
        }
      ]
    }
  },
  "size": 30,
  "sort": [
    {
      "_score": {
        "order": "desc"
      }
    }
  ]
}

as you can see I'm trying to use Field boosting using (^), now imagine I'm trying to search For 'xxx'. in the database i have this value in the FirstName Field and when i apply this query i would expect to see the result at the top 100 because i set the "FirstName^10" like this.

now i dont know why i dont get the correct result.

I have query like this:

{
  "query": {
    "bool": {
      "must": [
        {
          "term": {
            "IsDeleted": {
              "value": false
            }
          }
        },
        {
          "query_string": {
            "fields": [
              "FirstName^10",
              "LastName^10",
              "CompanyName^5",
              "MobilePhone^3",
              "MobilePhone^4",
              "ContactName^3",
              "CompanyName^3",
              "ContactMobilePhoneSearch^2",
              "CompanyName^2",
            ],
            "query": "/محمد(.*?)/ AND /محمد(ی|ي|ئ)(.*?)/"
          }
        }
      ]
    }
  },
  "size": 30,
  "sort": [
    {
      "_score": {
        "order": "desc"
      }
    }
  ]
}

as you can see I'm trying to use Field boosting using (^), now imagine I'm trying to search For 'xxx'. in the database i have this value in the FirstName Field and when i apply this query i would expect to see the result at the top 100 because i set the "FirstName^10" like this.

now i dont know why i dont get the correct result.

Share asked Jan 31 at 13:15 HassanJalaliHassanJalali 13113 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

It's because of how the BM25 algorithm works. Check the following article. https://www.elastic.co/blog/practical-bm25-part-2-the-bm25-algorithm-and-its-variables.

In addition, please check the explain API call to understand "how elasticsearch scoring works?". https://www.elastic.co/guide/en/elasticsearch/reference/current/search-explain.html

An example:

GET /my-index-000001/_explain/0
{
  "query" : {
    "match" : { "message" : "elasticsearch" }
  }
}

or

GET /my-index-000001/_search
{
  "explain": true,
  "query" : {
    "match" : { "message" : "elasticsearch" }
  }
}
转载请注明原文地址:http://anycun.com/QandA/1744860629a88643.html