Search code examples
elasticsearchsearchelastic-stackelasticsearch-dsl

Elasticsearch - Relevancy of search terms


How do you tell Elasticsearch that one full text field should be less relevant than other full text fields?

Suppose I have:

"query": {
            "bool": {
                "must": {
                    "query_string": {
                        "fields": ["my_id", "title^2", "intro", "body1", "body2", "body3", "footer"],
                        "default_operator": "AND",
                        "query": "some search query"
                    }
                }
            }
}

I want footer to be treated as less relevant than the others. What is the best approach to that?

Thanks


Solution

  • A boost value between 0 and 1.0 decreases the relevance score. So for example:

    {
      "query": {
        "bool": {
          "must": {
            "query_string": {
              "fields": [
                ...
                "footer^0.5"
              ],
              ...
            }
          }
        }
      }
    }
    

    should do the trick.