我在multi_match
使用phrase_prefix
进行Elasticsearch 5.5中的全文搜索。 ES查询看起来像
{
query: {
bool: {
must: {
multi_match: {
query: "butt",
type: "phrase_prefix",
fields: ["item.name", "item.keywords"],
max_expansions: 10
}
}
}
}
}
我收到了以下回复
[
{
"_index": "items_index",
"_type": "item",
"_id": "2",
"_score": 0.61426216,
"_source": {
"item": {
"keywords": "amul butter, milk, butter milk, flavoured",
"name": "Flavoured Butter"
}
}
},
{
"_index": "items_index",
"_type": "item",
"_id": "1",
"_score": 0.39063013,
"_source": {
"item": {
"keywords": "amul butter, milk, butter milk",
"name": "Butter Milk"
}
}
}
]
映射如下(我使用的是默认映射)
{
"items_index" : {
"mappings" : {
"parent_doc": {
...
"properties": {
"item" : {
"properties" : {
"keywords" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"name" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
}
}
}
}
}
}
}
item
"name": "Flavoured Butter"
0.61426216
对"name": "Butter Milk"
和0.39063013
的文档得分越高"item.name"
的方式如何?
我尝试将提升应用于"item.keywords"
并删除constructor(private http:Http){
let _build = (<any>this.http)._backend._browseXHR.build;
(<any>this.http)._backend._browseXHR.build = () => {
let _xhr = _build();
_xhr.withCredentials = true;
return (_xhr);
};
}
表单搜索字段,以获得相同的结果。
Elasticsearch的得分如何运作?上述结果在相关性方面是否正确?
答案 0 :(得分:0)
phrase_prefix
的得分与best_fields
的得分相似,这意味着文档得分是从best_field获得的得分,此处为item.keywords
。
因此,item.name
没有添加到分数
您可以使用2 multi_match
个查询来合并keywords
和name
的分数。
{
"query": {
"bool": {
"must": [{
"multi_match": {
"query": "butt",
"type": "phrase_prefix",
"fields": [
"item.keywords"
],
"max_expansions": 10
}
},{
"multi_match": {
"query": "butt",
"type": "phrase_prefix",
"fields": [
"item.name"
],
"max_expansions": 10
}
}]
}
}
}