如何提高弹性搜索中的索引类型? [英] How to boost index type in elasticsearch?
本文介绍了如何提高弹性搜索中的索引类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我曾经像这样搜索:
curl -XGET localhost:9200 / users / _search
但用户包含用户a,b,c,如下所示:
curl -XGET localhost:9200 / users / a,b,c / _search
but users contains user a,b,c like this:
curl -XGET localhost:9200/users/a,b,c/_search
用户
是第一个索引, a / b / c
请输入
users
is the first index, a/b/c
is type.
如何在此查询中提升类型 a
?
How to boost type a
in this query? Best with sample code, thanks.
推荐答案
您可以使用术语查询来提升索引类型。
You can boost index types using terms query.
首先创建一些测试数据(e1,e2,e3是类型,测试是索引名称):
First Create some test data (e1,e2,e3 are types and test is the index name):
PUT test/e1/1
{
"subject": "subject 1"
}
PUT test/e2/1
{
"subject": "subject 1"
}
PUT test/e3/1
{
"subject": "subject 1"
}
现在使用按类型定制提升的术语查询:
Now using term query with custom boost by type:
GET test/_search
{
"query": {
"bool": {
"should": [
{
"query_string": {
"query": "subject"
}
},
{ "term" : { "_type" : {"value" : "e3", "boost" : 2.0} } },
{ "term" : { "_type" : {"value" : "e2", "boost" : 3.0} } }
]
}
}
}
其中将生成如下结果:
{
"took": 1,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"failed": 0
},
"hits": {
"total": 3,
"max_score": 0.7671045,
"hits": [
{
"_index": "test",
"_type": "e2",
"_id": "1",
"_score": 0.7671045,
"_source": {
"subject": "subject 1"
}
},
{
"_index": "test",
"_type": "e3",
"_id": "1",
"_score": 0.59740055,
"_source": {
"subject": "subject 1"
}
},
{
"_index": "test",
"_type": "e1",
"_id": "1",
"_score": 0.1289963,
"_source": {
"subject": "subject 1"
}
}
]
}
}
这篇关于如何提高弹性搜索中的索引类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文