例如,假设我有一个带有CharField
的简单模型。我将其添加到Page.search_fields
为200的boost
中,如in the docs所述:
class TestModel(Page):
cool_name = models.CharField(max_length=50)
search_fields = Page.search_fields + [
index.SearchField('cool_name', boost=200),
]
...
当我使用Wagtail的内置ES6实现对单词pascal
进行简单查询时...
backend.search('pascal', Page)
...,并查看从ES生成的查询和响应,它似乎是bool
查询,没有说明提升的字段值(得分太低):
...
"_id": "100",
"_index": "wagtail__wagtailcore_page",
"_node": "mK2TtTfNRj-Dhw7RV0U49A",
"_score": 8.437754,
"_shard": "[wagtail__wagtailcore_page][1]",
"_source": {
...
},
...
当我直接针对ES API对pascal
运行简单查询时:
http://localhost:9200/wagtail__wagtailcore_page/_search?pretty=true&q=pascal&explain=true
我得到以下答复:
"total" : 1,
"max_score" : 262.495,
"hits" : [
{
"_index" : "wagtail__wagtailcore_page",
"_type" : "doc",
"_id" : "100",
"_score" : 262.495,
"_source" : {
....
},
"_explanation" : {
"value" : 262.495,
"description" : "max of:",
"details" : [
{
"value" : 262.495,
"description" : "weight(test_testmodel__cool_name:pascal in 60) [PerFieldSimilarity], result of:",
"details" : [
{
"value" : 262.495,
"description" : "score(doc=60,freq=1.0 = termFreq=1.0\n), product of:",
"details" : [
{
"value" : 200.0,
"description" : "boost",
"details" : [ ]
},
]
}
....
因此,将提升值正确地应用于term
查询,但使用内置ES6功能时却不能正确应用。这是预期的Wa行为吗?据我了解,这可能是由于Elasticsearch对boost
查询中的bool
字段进行了处理,但是文档暗示只需将boost
添加到SearchField
即可正常工作。>