elasticsearch - 如何在 Elasticsearch 查询字符串中转义特殊单词,例如 "AND"、 "OR"

标签 elasticsearch elasticsearch-dsl

我正在尝试构建一个elasticsearch 查询字符串查询。提到必须对保留字符或特殊字符进行转义。

https://www.elastic.co/guide/en/elasticsearch/reference/2.1/query-dsl-query-string-query.html#_reserved_characters

The reserved characters are: + - = && || > < ! ( ) { } [ ] ^ " ~ * ? : \ /

未能正确转义这些特殊字符可能会导致语法错误,从而阻止查询运行。”

我的问题是:如何转义“AND”或“OR”等“特殊词”。例如,我想获取与文本“现在或从不”(在所有/任何字段上)匹配并且状态为“事件”或“待处理”的文档。下面的查询似乎不起作用(或者没有被elasticsearch转义)。

NOW \OR NEVER status:(active OR pending) 

最佳答案

您可以尝试将文本用双引号引起来:

GET your_index/_search?q=status:(active OR pending) AND "NOW OR NEVER"

关于elasticsearch - 如何在 Elasticsearch 查询字符串中转义特殊单词,例如 "AND"、 "OR",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53164341/

相关文章:

Elasticsearch 和 Asp.Net Core

elasticsearch - ElasticSearch使用空格搜索带连字符的文本,而不是查询中的破折号

elasticsearch - 如何调整日期字段上的日期范围聚合值?

django - 通过地理空间数据排序并基于字段向上移动特定记录-ElasticSearch DSL DRF

elasticsearch - 复合Elasticsearch过滤器中的inner_hits空

elasticsearch - Elasticsearch 查询可以有空值参数吗?

amazon-web-services - AWS ElasticSearchService index_create_block_exception

apache-spark - pyspark将数据写入elasticsearch时将日期类型保存为长类型

python - 尝试使用elasticsearch-dsl Python软件包访问Elasticsearch Cloud时的“Failed to establish a new connection”

python - 结合使用flask(或elasticsearch)和Node.js Web服务器是否有意义?