elasticsearch boost importance of exact phrase match

前端 未结 5 932
无人共我
无人共我 2020-12-25 15:12

Is there a way in elasticsearch to boost the importance of the exact phrase appearing in the the document?

For example if I was searching for the phrase \"web develo

5条回答
  •  萌比男神i
    2020-12-25 15:47

    As an alternative to javanna's answer, you could do something similar with must and should clauses within a bool query:

    {
      "query": {
        "bool": {
          "must": {
              "match": {
                "field": "web developer",
                "operator": "and"
              }
          },
          "should": {
              "match_phrase": {
                "field": "web developer"
              }
          }
        }
      }
    }
    

    Untested, but I believe the must clause here will match results containing both 'web' and 'developer' and the should clause will score phrases matching 'web developer' higher.

提交回复
热议问题