[英]Give document fields different priority in ElasticSearch
I have data:我有数据:
{"NAME": "BRIDGE CAMBODJA", "NAME": "CAMBRIDGE APARTMENTS", "NAME":"KULAMAN BRIDGE"}
I have the following query:我有以下查询:
'{"query": {"query_string": {"query": "BRIDGE"}'
and I want what will appear is:我想要出现的是:
{"NAME": "BRIDGE CAMBODJA", "NAME": "KULAMAN BRIDGE", "NAME": "CAMBRIDGE APARTMENTS"}
How do I modify my search to set the field ranking / priority?如何修改我的搜索以设置字段排名/优先级?
You can achieve your required result, by using the boost parameter directly in the query and querying for NAME
which begins with BRIDGE
, ends with BRIDGE
, or which contains BRIDGE
.您可以通过直接在查询中使用boost 参数并查询以
BRIDGE
开头、以BRIDGE
结尾或包含BRIDGE
的NAME
来实现所需的结果。
Adding a working example添加一个工作示例
Index Mapping:索引映射:
{
"mappings": {
"properties": {
"NAME": {
"type": "keyword"
}
}
}
}
Search Query:搜索查询:
{
"query": {
"bool": {
"should": [
{
"query_string": {
"default_field": "NAME",
"query": "BRIDGE*",
"boost": 10
}
},
{
"query_string": {
"default_field": "NAME",
"query": "*BRIDGE",
"boost": 5
}
},
{
"query_string": {
"default_field": "NAME",
"query": "*BRIDGE*",
"boost": 1
}
}
]
}
}
}
Search Result:搜索结果:
"hits": [
{
"_index": "66095448",
"_type": "_doc",
"_id": "1",
"_score": 11.0,
"_source": {
"NAME": "BRIDGE CAMBODJA"
}
},
{
"_index": "66095448",
"_type": "_doc",
"_id": "3",
"_score": 6.0,
"_source": {
"NAME": "KULAMAN BRIDGE"
}
},
{
"_index": "66095448",
"_type": "_doc",
"_id": "2",
"_score": 1.0,
"_source": {
"NAME": "CAMBRIDGE APARTMENTS"
}
}
]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.