gpt4 book ai didi

elasticsearch - Elasticsearch无法解析查询无法解析 'OR'

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

我正在尝试从索引中搜索文档中的单词“OR”。
这是我输入的查询

GET index_name/_search
{
"query": {
"bool": {
"filter": [
{
"query_string": {
"query": "OR word1",
"fields": [
"field1"
]
}
}
]
}
}
}
我收到以下错误
{
"error": {
"root_cause": [
{
"type": "query_shard_exception",
"reason": "Failed to parse query [OR word1]",
"index_uuid": "Brju2MNeQ5m7sI02Q2Y4gw",
"index": "index_name"
}
],
"type": "search_phase_execution_exception",
"reason": "all shards failed",
"phase": "query",
"grouped": true,
"failed_shards": [
{
"shard": 0,
"index": "index_name",
"node": "C5Suw-gaR7eehoH0WNGw1A",
"reason": {
"type": "query_shard_exception",
"reason": "Failed to parse query [OR word1]",
"index_uuid": "Brju2MNeQ5m7sI02Q2Y4gw",
"index": "index_name",
"caused_by": {
"type": "parse_exception",
"reason": "Cannot parse 'OR word1': Encountered \" <OR> \"OR \"\" at line 1, column 0.\nWas expecting one of:\n <NOT> ...\n \"+\" ...\n \"-\" ...\n <BAREOPER> ...\n \"(\" ...\n \"*\" ...\n <QUOTED> ...\n <TERM> ...\n <PREFIXTERM> ...\n <WILDTERM> ...\n <REGEXPTERM> ...\n \"[\" ...\n \"{\" ...\n <NUMBER> ...\n <TERM> ...\n ",
"caused_by": {
"type": "parse_exception",
"reason": "Encountered \" <OR> \"OR \"\" at line 1, column 0.\nWas expecting one of:\n <NOT> ...\n \"+\" ...\n \"-\" ...\n <BAREOPER> ...\n \"(\" ...\n \"*\" ...\n <QUOTED> ...\n <TERM> ...\n <PREFIXTERM> ...\n <WILDTERM> ...\n <REGEXPTERM> ...\n \"[\" ...\n \"{\" ...\n <NUMBER> ...\n <TERM> ...\n "
}
}
}
}
]
},
"status": 400
}
为什么这是一个错误?如何克服这个错误?如果我从查询中删除单词“Or”,它可以正常工作,但是当我保留它时,会出现此错误

最佳答案

如果我很好地理解了您的问题,我创建了一个索引,并提取了两个文档。我试图使用escape字符= \\提出建议
这是我摄取的数据:
“field1”:“word1”
“field1”:“或word1”
然后,我对您的查询做了一些小的修改:

{
"query": {
"bool": {
"filter": [
{
"query_string": {
"query": "word1 \\OR",
"fields": ["field1"]
}
}
]
}
}
}
响应是:
"hits" : [
{
"_index" : "or-doc",
"_type" : "_doc",
"_id" : "9mCioHQBowpsxTkF3Jdx",
"_score" : 0.0,
"_source" : {
"field1" : "word1"
}
},
{
"_index" : "or-doc",
"_type" : "_doc",
"_id" : "82CjoHQBowpsxTkFCZgE",
"_score" : 0.0,
"_source" : {
"field1" : "OR word1"
}
}
]
注意:我逃避了 OR,因为它被视为 reserved words
如果您有任何问题,我们将很乐意为您提供帮助。
链接: https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-query-string-query.html

关于elasticsearch - Elasticsearch无法解析查询无法解析 'OR',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63952836/

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