gpt4 book ai didi

elasticsearch - 在elasticsearch中匹配两个字符串数组

转载 作者:行者123 更新时间:2023-12-02 22:26:55 24 4
gpt4 key购买 nike

我是Elasticsearch的新手,
并在elasticsearch中使用field:tags["tag1","tag2","tag3","color2","color1"]
我要将我的标签数组与db中的字段标签进行匹配,以使最小标签的50%匹配。

{
"query": {
"bool": {
"must": [
{
"terms": {
"tags": [
"tag1",
"tag2",
"tag3"
],
"boost": 1.0
}
}
],
"adjust_pure_negative": true,
"minimum_should_match": "50%",
"boost": 1.0
}
}
}
它不起作用

最佳答案

您需要在order百分比属性中添加不同的should子句才能使用,并添加以下示例示例,类似于您必须显示的示例:
索引映射

{
"mappings": {
"properties": {
"tags": {
"type": "text"
}
}
}
}
索引样本文档
{
"tags" : ["tag1", "tag2", "tag3", "tag4", "tag5"]
}
搜索查询,其中超过50%的匹配标签返回doc
{
"query": {
"bool" : {
"should" : [
{ "term" : { "tags" : "tag1" } },
{ "term" : { "tags" : "tag2" } },
{ "term" : { "tags" : "tag3" } },
{ "term" : { "tags" : "tag8" } }
],
"minimum_should_match" : "50%",
"boost" : 1.0
}
}
}
搜索结果
"hits": [
{
"_index": "tags",
"_type": "_doc",
"_id": "1",
"_score": 1.0,
"_source": {
"tags": [
"tag1",
"tag2",
"tag3",
"tag4",
"tag5"
]
}
}
不会带来50%搜索结果的示例
{
"query": {
"bool" : {
"should" : [
{ "term" : { "tags" : "tag1" } },
{ "term" : { "tags" : "tag6" } },
{ "term" : { "tags" : "tag7" } },
{ "term" : { "tags" : "tag8" } }
],
"minimum_should_match" : "50%",
"boost" : 1.0
}
}
}

关于elasticsearch - 在elasticsearch中匹配两个字符串数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62951121/

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