gpt4 book ai didi

elasticsearch - 转义Elasticsearch查询时遇到麻烦

转载 作者:行者123 更新时间:2023-12-03 00:54:49 25 4
gpt4 key购买 nike

在ES 5中,假设我要搜索“yabba / dabba”。 docs提到使用反斜杠转义保留字符。但是,如果这样做,我会得到一个错误。执行此查询将返回错误:

curl -XPOST "http://127.0.0.1:9200/messages/_search?pretty=true" --data-binary '{
"query": {
"bool": {
"must": [
{
"bool" : {
"should" : [
{
"query_string" : {
"query" : "yabba\/dabba"
}
}
]
}
}
]
}
}
}'

返回的错误的相关部分是:
        "reason" : {
"type" : "query_shard_exception",
"reason" : "Failed to parse query [yabba/dabba]",
"index_uuid" : "hhldqVnWSDelNyMdtiF0kw",
"index" : "messages_201708291329",
"caused_by" : {
"type" : "parse_exception",
"reason" : "Cannot parse 'yabba/dabba': Lexical error at line 1, column 12. Encountered: <EOF> after : \"/dabba\"",
"caused_by" : {
"type" : "token_mgr_error",
"reason" : "Lexical error at line 1, column 12. Encountered: <EOF> after : \"/dabba\""
}
}

最佳答案

您还需要转义反斜杠本身,因为它位于字符串中。这将起作用:

curl -XPOST "http://127.0.0.1:9200/messages/_search?pretty=true" --data-binary '{
"query": {
"bool": {
"must": [
{
"bool" : {
"should" : [
{
"query_string" : {
"query" : "yabba\\/dabba"
}
}
]
}
}
]
}
}
}'

关于elasticsearch - 转义Elasticsearch查询时遇到麻烦,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45948547/

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