gpt4 book ai didi

elasticsearch - ElasticSearch多词查询,匹配多个词比匹配几次但多次匹配更有值(value)

转载 作者:行者123 更新时间:2023-12-03 01:16:20 26 4
gpt4 key购买 nike

我在ElasticSearch中编写了一个多词搜索查询,匹配多个词比匹配1多次更有值(value)。

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
}
}

当我搜索“有效OR日期”时

例如:

"This is an example date for effective calculation of the problems"



分数应高于:

"date date date is what he said to the children"



我如何对此进行微调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

更新1:

使用query_string
    {
"query": {
"query_string": {
"default_field": "title",
"query": "effective OR date"
}
}
}

要获取query_string的详细说明,您可以引用 this

更新2:

使用simple_query_string
{
"query": {
"simple_query_string" : {
"query": "effective date",
"fields": ["title"],
"default_operator": "or"
}
}
}

通过使用以上所有三个搜索查询,您将获得相同的搜索结果,并且_score 没有区别

关于elasticsearch - ElasticSearch多词查询,匹配多个词比匹配几次但多次匹配更有值(value),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62420458/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com