match_phrase_prefix返回结果如何使越靠前的单词占有的权重越高,排序更靠前

Elasticsearch | 作者 Han_ | 发布于2021年12月08日 | 阅读数:247

GET /facility_search_test/_search
{
"query": {
"match_phrase_prefix": {
"address": {
"query": "11575",
"boost": 1,
"analyzer": "my_synonyms"
}
}
}
}

以上是我的dsl
{
  "took": 1,
  "timed_out": false,
  "_shards": {
    "total": 1,
    "successful": 1,
    "skipped": 0,
    "failed": 0
  },
  "hits": {
    "total": 12,
    "max_score": 10.836019,
    "hits": [
      {
        "_index": "facility_search",
        "_type": "facility_search",
        "_id": "AX1Z3DMBWXp1KnQKVYmC",
        "_score": 10.836019,
        "_source": {
          "address": "144 Nassau Rd Roosevelt, NY 11575 USA"
        }
      },
      {
        "_index": "facility_search",
        "_type": "facility_search",
        "_id": "AX1Z56sqWXp1KnQKVxJF",
        "_score": 10.836019,
        "_source": {
          "address": "322 Nassau Rd Roosevelt, NY 11575 USA"
        }
      },
      {
        "_index": "facility_search",
        "_type": "facility_search",
        "_id": "1111621",
        "_score": 10.836019,
        "_source": {
          "address": "144 Nassau Rd Roosevelt, NY 11575 USA"
        }
      },
      {
        "_index": "facility_search",
        "_type": "facility_search",
        "_id": "1204438",
        "_score": 10.836019,
        "_source": {
          "address": "322 Nassau Rd Roosevelt, NY 11575 USA"
        }
      },
      {
        "_index": "facility_search",
        "_type": "facility_search",
        "_id": "AX1Z4Si-WXp1KnQKVfz0",
        "_score": 9.298623,
        "_source": {
          "address": "11575 E 40th Ave, Denver, CO 80239-3376, United States"
        }
      },
      {
        "_index": "facility_search",
        "_type": "facility_search",
        "_id": "AX1Z6u3sWXp1KnQKV1OW",
        "_score": 9.298623,
        "_source": {
          "address": "11575 Reading Rd, Cincinnati, OH 45241-2240, United States"
        }
      },
      {
        "_index": "facility_search",
        "_type": "facility_search",
        "_id": "AX1Z8wQMWXp1KnQKWGt4",
        "_score": 9.298623,
        "_source": {
          "address": "208 Babylon Turnpike, Roosevelt, NY 11575, United States"
        }
      },
      {
        "_index": "facility_search",
        "_type": "facility_search",
        "_id": "AX1Z5LlSWXp1KnQKVte-",
        "_score": 9.298623,
        "_source": {
          "address": "11575 Reading Rd, Cincinnati, OH 45241, United States"
        }
      },
      {
        "_index": "facility_search",
        "_type": "facility_search",
        "_id": "AX1Z4SjOWXp1KnQKVhT5",
        "_score": 9.298623,
        "_source": {
          "address": "11575 W President Dr Boise, ID 83713 USA"
        }
      },
      {
        "_index": "facility_search",
        "_type": "facility_search",
        "_id": "AX1Z8DNeWXp1KnQKWBKp",
        "_score": 9.298623,
        "_source": {
          "address": "11575 Main St #300, Broomfield, CO 80020, United States"
        }
      }
    ]
  }
}

以上是返回结果。
我希望以11575开头的排在前边
已邀请:

God_lockin

赞同来自: xiaowuge

加个prefix 进去调整下分数呢
{
"query": {
"bool": {
"should": [
{
"match_phrase_prefix": ...
},
{
"prefix": {
"query": "11575",
"boost": 100
}
}
]
}
}
}

xiaowuge - 90后

赞同来自: caster_QL

解决办法:通过修改打分,根据词条的position来修改打分。
如果你版本是5.X 请参考这个:


 如果你版本是6.X以上请参考这个:

要回复问题请先登录注册