elasticsearch 如何在elasticsearch中使用冒号搜索模式?
我在Elasticsearch中有一个字段,其值为“ft:05/08/2015 13:01:27.358,cgn:4189”。 当我想用查询字符串“cgn:4189”搜索时,我没有结果。 我试图像“cgn:4189”一样转义冒号,但我有一个语法错误。 我不知道怎么做
elasticsearch 如何在elasticsearch中使用冒号搜索模式?,
elasticsearch,
elasticsearch,我在Elasticsearch中有一个字段,其值为“ft:05/08/2015 13:01:27.358,cgn:4189”。 当我想用查询字符串“cgn:4189”搜索时,我没有结果。 我试图像“cgn:4189”一样转义冒号,但我有一个语法错误。 我不知道怎么做 {"query":{"bool":{"must":[{"query_string":{"default_field":"fluentd.message","query":"cgn:"}}],"must_not":[],"should
{"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
JSON.parse: bad escaped character at line 1 column 91 of the JSON data
及
结果:
"error": "SearchPhaseExecutionException[Failed to execute phase [query], all shards failed; shardFailures
JSON.parse: bad escaped character at line 1 column 91 of the JSON data
您能帮我吗?试试这个查询,看看它是否适合您:
{
"query": {
"bool": {
"must": [
{
"query_string": {
"default_field": "fluentd.message",
"query": "cgn\\:4189"
}
}
],
"must_not": [],
"should": []
}
},
"from": 0,
"size": 10,
"sort": [],
"facets": {}
}
下面是我用来测试它的一些感觉代码:
如果这对您不起作用,那么它可能与您的映射和/或分析设置有关。因此,如果您可以在您的问题中发布您的映射,包括任何自定义分析器,它将有所帮助。此外,正确设置代码块的格式将使它们更易于阅读。引用时,只需在查询中添加转义双引号即可:
{
"query": {
"query_string" : {
"query": "ip_addr:\"2001:db8::/48\""
}
}
}
伟大的非常感谢。