【发布时间】:2015-02-14 06:15:18
【问题描述】:
我希望能够为在任何字段中找到的每个搜索词添加前缀查询,并且我希望能够突出显示。我制定了一个似乎有效的查询。现在,我想更新查询,以便其中一个字段中的匹配产生比其他字段中的匹配更高的分数。
例如我索引以下数据(这只是一个示例,在我的真实数据中,除了两个之外还有更多字段):
PUT /my_index/my_type/abc124 { “标题”:“废话”, “描述”:“高尔夫” }
PUT /my_index/my_type/abc123 { “标题”:“等等高尔夫”, “描述”:“课程” }
PUT /my_index/my_type/abc125 { "title" : "blah 高尔夫球座", “描述”:“课程” }
然后我可以使用如下查询进行查询:
POST my_index/my_type/_search
{
"query": {
"bool": {
"must": [
{
"prefix": {
"_all" : "gol"
}
},
{
"prefix": {
"_all": "bla"
}
}
]
}
},
"highlight":{
"fields":{
"*":{}
}
}
}
产生结果:
{
"took": 11,
"timed_out": false,
"_shards": {
"total": 4,
"successful": 4,
"failed": 0
},
"hits": {
"total": 3,
"max_score": 1.4142135,
"hits": [
{
"_index": "my_index",
"_type": "my_type",
"_id": "abc125",
"_score": 1.4142135,
"_source": {
"title": "blah golf tee",
"description": "course"
},
"highlight": {
"title": [
"<em>blah</em> <em>golf</em> tee"
]
}
},
{
"_index": "my_index",
"_type": "my_type",
"_id": "abc124",
"_score": 1.4142135,
"_source": {
"title": "blah",
"description": "golf"
},
"highlight": {
"description": [
"<em>golf</em>"
],
"title": [
"<em>blah</em>"
]
}
},
{
"_index": "my_index",
"_type": "my_type",
"_id": "abc123",
"_score": 1.4142135,
"_source": {
"title": "blah golf",
"description": "course"
},
"highlight": {
"title": [
"<em>blah</em> <em>golf</em>"
]
}
}
]
}
}
如何使用 function_score 或其他方式修改评分,以便我可以在 title 字段上的匹配得分高于其他字段?我是否需要将查询更改为多重匹配而不是使用 _all?任何建议将不胜感激。
问候, LT
【问题讨论】:
标签: elasticsearch