我有以下查询:
{
"query": {
"match": {
"message": {
"query": "Error",
"type": "phrase"
}
}
}
}
但是我得到的结果包含了我不感兴趣的特定内容。
例如:
2017-12-05 15:51:54,012 ERROR io.vertx.spi.cluster.zookeeper.ZookeeperClusterManager - Failed to handle memberRemoved
io.vertx.core.VertxException: java.io.InvalidClassException: io.vertx.spi.cluster.zookeeper.impl.ZKSyncMap$KeyValue; local class
所以我想升级我的查询而不是返回包含单词的结果:ZookeeperClusterManager
我如何使用当前查询执行此操作?
谢谢
答案 0 :(得分:0)
您需要将boolean query与must_not
一起用于否定搜索。
查询应该是这样的
{
"query": {
"bool": {
"must": {
"match": {
"message": "Error"
}
},
"must_not": {
"match": {
"message": "io.vertx.spi.cluster.zookeeper.ZookeeperClusterManager"
}
}
}
}
}
您需要使用io.vertx.spi.cluster.zookeeper.ZookeeperClusterManager
,因为ES中的索引工作原理。 ES使用分析器将长字符串转换为可以搜索的值列表。其中一个步骤是按空格分割文本(标记化)。这就是这里发生的事情。
2017-12-05 15:51:54,012 ERROR io.vertx.spi.cluster.zookeeper.ZookeeperClusterManager - Failed to handle memberRemoved
转换为以下列表
2017-12-05
15:51:54,012
ERROR
io.vertx.spi.cluster.zookeeper.ZookeeperClusterManager
-
Failed
to
handle
memberRemoved
这就是为什么您搜索error
有效,但搜索ZookeeperClusterManager
却没有。 ZookeeperClusterManager
本身不在列表中。有关分析如何工作的更多信息,我建议您read this blogpost on ES website。通常,您可以通过使用空格和点而不是空格来使标记化器标记化来解决此问题。如何设置自定义分析是described in this blogpost。