我正在ElasticSearch中编写一个多词搜索查询,匹配多个词比匹配1多次更有价值。
1个跨几个字段的查询:
{
"bool" : {
"must" : [
{
"simple_query_string" : {
"query" : "effective date ",
"fields" : [
"field1^1.0",
"field2^5.0",
"field3^10.0",
],
"flags" : -1,
"default_operator" : "or",
"analyze_wildcard" : false,
"auto_generate_synonyms_phrase_query" : true,
"fuzzy_prefix_length" : 0,
"fuzzy_max_expansions" : 50,
"fuzzy_transpositions" : true,
"boost" : 1.0
}
}
],
"adjust_pure_negative" : true,
"boost" : 1.0
}
}
当我搜索“有效或日期”时
例如:
“这是有效问题计算的示例日期”
分数应高于:
“ 日期日期日期是他对孩子们所说的”
我如何对此进行微调elasticsearch?
谢谢!
因为您没有在索引中提到多少个字段的问题,所以我只选取了一个字段,即title
索引文件:
{
"title":"This is an example date for effective calculation of the problems"
}
{
"title":"date date date is what he said to the children"
}
搜索查询:
{
"query": {
"bool": {
"must": [
{
"multi_match": {
"query": "effective date",
"operator": "or",
"fields": [
"title" --> If you have more fields, you can
add them here
]
}
}
]
}
}
}
搜索结果:
"hits": [
{
"_index": "my_index",
"_type": "_doc",
"_id": "1",
"_score": 0.85874003,
"_source": {
"title": "This is an example date for effective calculation of the problems"
}
},
{
"_index": "my_index",
"_type": "_doc",
"_id": "2",
"_score": 0.289459,
"_source": {
"title": "date date date is what he said to the children"
}
}
]
要获取有关多匹配查询的详细说明,您可以参考此官方documentation