gpt4 book ai didi

elasticsearch - 为什么这个Elasticsearch查询不完全匹配字符串?

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

我有一个Elasticsearch查询,该查询与它应该匹配的文档不匹配。

这是查询:

POST _search
{
"query": {
"filtered": {
"filter": {
"bool": {
"must": {
"term": {
"signupCompany": "NewBay Media"
}
}
}
}
}
}
}

但是,如果我将术语更改为:
"signupCompanyID": 643

然后找到正确的文档。这是我的映射:
"properties": {
"body": {
"type": "string"
},
"datetimeIndexed": {
"type": "date",
"format": "epoch_millis||yyyy/MM/dd HH:mm:ss||yyyy/MM/dd"
},
"datetimeReceived": {
"type": "date",
"format": "epoch_millis||yyyy/MM/dd HH:mm:ss||yyyy/MM/dd"
},
"duplicateOfEmailID": {
"type": "long"
},
"enabled": {
"type": "boolean"
},
"htmlBodyPath": {
"type": "string"
},
"plainBodyPath": {
"type": "string"
},
"secondsAgoReceived": {
"type": "long"
},
"senderName": {
"type": "string",
"fields": {
"raw": {
"type": "string",
"index": "not_analyzed"
}
}
},
"signupCompany": {
"type": "string"
},
"signupCompanyEnabled": {
"type": "boolean"
},
"signupCompanyID": {
"type": "long"
},
"signupCompanyInitial": {
"type": "string"
},
"subject": {
"type": "string"
}
}

我还有一些其他查询已经在使用中并且正在使用datetimeReceived字段和enabled字段进行生产,但无法使此特定字符串匹配正常工作。

它不适用于任何signupCompany,不仅限于此。

最佳答案

您需要将signupCompany的映射类型设置为not_analyzed,以便它不尝试匹配部分字符串,仅匹配确切的值。 -文档:https://www.elastic.co/guide/en/elasticsearch/guide/current/mapping-intro.html

"signupCompany": {
"type": "string",
"index": "not_analyzed"
}

关于elasticsearch - 为什么这个Elasticsearch查询不完全匹配字符串?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34712845/

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