如何在elasticsearch中使用冒号搜索模式? [英] How to search pattern with colon in elasticsearch?

查看:163
本文介绍了如何在elasticsearch中使用冒号搜索模式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Elasticsearch中有一个值为 ft:05/08/2015 13:01:27.358,cgn:4189 的字段。
当我想使用查询字符串 cgn:4189进行搜索时,我没有结果。
我尝试像 cgn:4189那样转义冒号,但是我有一个语法错误。
我不知道该怎么做。

I have a field in Elasticsearch with the value "ft:05/08/2015 13:01:27.358,cgn:4189" . When I want to search with query string "cgn:4189" i have no result . I try to escape the colon like "cgn:4189" but i have a syntax error . I don't know how to do this .

{"query":{"bool":{"must":[{"query_string":{"default_field":"fluentd.message","query":"cgn:"}}],"must_not":[],"should":[]}},"from":0,"size":10,"sort":[],"facets":{}}

结果:

"error": "SearchPhaseExecutionException[Failed to execute phase [query], all shards failed; shardFailures

{"query":{"bool":{"must":[{"query_string":{"default_field":"fluentd.message","query":"cgn\:"}}],"must_not":[],"should":[]}},"from":0,"size":10,"sort":[],"facets":{}}

结果:

JSON.parse: bad escaped character at line 1 column 91 of the JSON data

第1行第91列有错误的转义字符?

Can you help me please?

推荐答案

尝试此查询,看看它是否对您有用:

Try this query and see if it works for you:

{
   "query": {
      "bool": {
         "must": [
            {
               "query_string": {
                  "default_field": "fluentd.message",
                  "query": "cgn\\:4189"
               }
            }
         ],
         "must_not": [],
         "should": []
      }
   },
   "from": 0,
   "size": 10,
   "sort": [],
   "facets": {}
}

下面是一些我用来测试的Sense代码:

Here is some Sense code I used to test it:

< a href = http://sense.qbox.io/gist/1c90964da37d3dfec47d76288885db5793f38415 rel = noreferrer> http://sense.qbox.io/gist/1c90964da37d3dfec47d76288885db5793f38415

如果这对您不起作用,则可能与您的映射和/或分析设置有关。因此,如果您可以发布映射(包括任何自定义分析器),则对您的问题有所帮助。另外,正确格式化代码块会使它们更易于阅读。

If that doesn't work for you, then it probably has something to do with your mapping and/or analysis setup. So if you could post your mapping, including any custom analyzers, in your question it will help. Also, properly formatting your code blocks would make them much easier to read.

这篇关于如何在elasticsearch中使用冒号搜索模式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆