gpt4 book ai didi

elasticsearch - 查询参数Elasticsearch中使用AND的问题

转载 作者:行者123 更新时间:2023-12-03 01:47:46 25 4
gpt4 key购买 nike

我一直在使用query_string过滤出结果。现在的问题是,当我尝试将查询字符串用作“我喜欢我的工作和我的老板”时, Elasticsearch 将AND视为运算符,而我的结果却出错了。

但是,在这种情况下,AND不是运算符。

如何判断AND不是运算符,它是Elasticsearch的字符串。任何解决此问题的方法都会有很大帮助。

提前致谢。

编辑1
(请求参数)

{
"_source": ["customer.ezPayId", "customer.billingContact.name", "customer.serviceContact.name", "customer.wmMetaData.library"],
"query": {
"bool": {
"must_not": [{
"term": {
"customer.lob": {
"value": "residential"
}
}
}],
"should": [{
"query_string": {
"query": "ROCHESTER GAS AND ELECTRIC"
}
},
{
"regexp": {
"customer.serviceContact.name_ivr": "ROCHESTER GAS AND ELECTRIC<0-999>"
}
}, {
"regexp": {
"customer.billingContact.name_ivr": "ROCHESTER GAS AND ELECTRIC<0-999>"
}
}, {
"regexp": {
"customer.serviceContact.name_ivr": ".<0-999>ROCHESTER GAS AND ELECTRIC"
}
}, {
"regexp": {
"customer.billingContact.name_ivr": ".<0-999>ROCHESTER GAS AND ELECTRIC"
}
}, {
"regexp": {
"customer.serviceContact.name_ivr": "ROCHESTER GAS AND ELECTRIC[0-9-',(/)@%#&*$!^+_|]"
}
}, {
"regexp": {
"customer.billingContact.name_ivr": "ROCHESTER GAS AND ELECTRIC[0-9-',(/)@%#&*$!^+_|]"
}
}]
}
},
"filter": {
"or": [{

{
"term": {
"customer.billingContact.name_ivr": "ROCHESTER GAS AND ELECTRIC"
}
}, {
"term": {
"customer.serviceContact.name_ivr": "ROCHESTER GAS AND ELECTRIC"
}
}, {
"regexp": {
"customer.serviceContact.name_ivr": "ROCHESTER GAS AND ELECTRIC<0-999>"
}
}, {
"regexp": {
"customer.billingContact.name_ivr": "ROCHESTER GAS AND ELECTRIC<0-999>"
}
}, {
"regexp": {
"customer.serviceContact.name_ivr": ".<0-999>ROCHESTER GAS AND ELECTRIC"
}
}, {
"regexp": {
"customer.billingContact.name_ivr": ".<0-999>ROCHESTER GAS AND ELECTRIC"
}
}, {
"regexp": {
"customer.serviceContact.name_ivr": "[0-9-',(/)@%#&*$!^+_| ].+ROCHESTER GAS AND ELECTRIC"
}
}, {
"regexp": {
"customer.billingContact.name_ivr": "[0-9-',(/)@%#&*$!^+_| ].+ROCHESTER GAS AND ELECTRIC"
}
}, {
"regexp": {
"customer.serviceContact.name_ivr": "ROCHESTER GAS AND ELECTRIC[0-9-',(/)@%#&*$!^+_| ].+"
}
}, {
"regexp": {
"customer.billingContact.name_ivr": "ROCHESTER GAS AND ELECTRIC[0-9-',(/)@%#&*$!^+_| ].+"
}
}, {
"regexp": {
"customer.serviceContact.name_ivr": "(.*) ROCHESTER GAS AND ELECTRIC (.*)"
}
}, {
"regexp": {
"customer.billingContact.name_ivr": "(.*) ROCHESTER GAS AND ELECTRIC (.*)"
}
}]
}
}

最佳答案

正如弗拉基米尔(Vladimir)所建议的那样,如果不需要“AND”运算符,则不得在应子句中使用“query_string”查询。仅当您要在查询字符串中使用AND,OR,NOT运算符时,才使用query_string查询。
然后,您应将其替换为“匹配”查询。

您需要更换

"should": [{
"query_string": {
"query": "ROCHESTER GAS AND ELECTRIC"
}
}

通过
"should": [{
"match": {
"_all": "ROCHESTER GAS AND ELECTRIC"
}
}

您的查询将如下所示:
{
"_source": ["customer.ezPayId", "customer.billingContact.name", "customer.serviceContact.name", "customer.wmMetaData.library"],
"query": {
"bool": {
"must_not": [{
"term": {
"customer.lob": {
"value": "residential"
}
}
}],
"should": [{
"match": {
"_all": "ROCHESTER GAS AND ELECTRIC"
}
},
{
"regexp": {
"customer.serviceContact.name_ivr": "ROCHESTER GAS AND ELECTRIC<0-999>"
}
}, {
"regexp": {
"customer.billingContact.name_ivr": "ROCHESTER GAS AND ELECTRIC<0-999>"
}
}, {
"regexp": {
"customer.serviceContact.name_ivr": ".<0-999>ROCHESTER GAS AND ELECTRIC"
}
}, {
"regexp": {
"customer.billingContact.name_ivr": ".<0-999>ROCHESTER GAS AND ELECTRIC"
}
}, {
"regexp": {
"customer.serviceContact.name_ivr": "ROCHESTER GAS AND ELECTRIC[0-9-',(/)@%#&*$!^+_|]"
}
}, {
"regexp": {
"customer.billingContact.name_ivr": "ROCHESTER GAS AND ELECTRIC[0-9-',(/)@%#&*$!^+_|]"
}
}]
}
},
"filter": {
"or": [{

{
"term": {
"customer.billingContact.name_ivr": "ROCHESTER GAS AND ELECTRIC"
}
}, {
"term": {
"customer.serviceContact.name_ivr": "ROCHESTER GAS AND ELECTRIC"
}
}, {
"regexp": {
"customer.serviceContact.name_ivr": "ROCHESTER GAS AND ELECTRIC<0-999>"
}
}, {
"regexp": {
"customer.billingContact.name_ivr": "ROCHESTER GAS AND ELECTRIC<0-999>"
}
}, {
"regexp": {
"customer.serviceContact.name_ivr": ".<0-999>ROCHESTER GAS AND ELECTRIC"
}
}, {
"regexp": {
"customer.billingContact.name_ivr": ".<0-999>ROCHESTER GAS AND ELECTRIC"
}
}, {
"regexp": {
"customer.serviceContact.name_ivr": "[0-9-',(/)@%#&*$!^+_| ].+ROCHESTER GAS AND ELECTRIC"
}
}, {
"regexp": {
"customer.billingContact.name_ivr": "[0-9-',(/)@%#&*$!^+_| ].+ROCHESTER GAS AND ELECTRIC"
}
}, {
"regexp": {
"customer.serviceContact.name_ivr": "ROCHESTER GAS AND ELECTRIC[0-9-',(/)@%#&*$!^+_| ].+"
}
}, {
"regexp": {
"customer.billingContact.name_ivr": "ROCHESTER GAS AND ELECTRIC[0-9-',(/)@%#&*$!^+_| ].+"
}
}, {
"regexp": {
"customer.serviceContact.name_ivr": "(.*) ROCHESTER GAS AND ELECTRIC (.*)"
}
}, {
"regexp": {
"customer.billingContact.name_ivr": "(.*) ROCHESTER GAS AND ELECTRIC (.*)"
}
}]
}
}

关于elasticsearch - 查询参数Elasticsearch中使用AND的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42535837/

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