Elasticsearch: Giving higher score to repetitive field than exact field

  Kiến thức lập trình

I have an Elasticsearch database in which all documents have a name field and are queried by this field.

By default, Elasticsearch search gives higher score to document with repetitive name. But, in my case, I am trying to get exact with high score.

For Example when I search for ‘pencil’ results are like that:

  1. name: “pencil pencil”
  2. name: “pencil”

so 2.score lower than 1.

I have tried query

{
    "query": {
        "bool": {
            "should": [
                {
                    "bool": {
                        "should": {
                            "query_string": {
                                "query": "+red ",
                                "default_field": "type"
                            }
                        }
                    }
                }
            ],
            "must": [
                {
                    "bool": {
                        "should": [
                            {
                                "query_string": {
                                    "query": "+pencil ",
                                    "default_field": "name"
                                }
                            }
                        ]
                    }
                }
            ]
        }
    }
}

LEAVE A COMMENT