对具有多个IP的文档进行多匹配查询

时间:2015-12-23 10:06:31

标签: elasticsearch

我有以下示例文档:

doc1
{
 "privateIp": "172.31.97.21",
 "instanceType": "production",
 "publicIp": "172.31.8.12",
 "avZone": "cmp019",
 "instanceId": "i-00000039",
 "instanceState": "running",
 "description": "common node"
}

doc2
{
 "privateIp": "172.31.97.12",
 "instanceType": "production",
 "publicIp": "172.31.8.4",
 "avZone": "cmp019",
 "instanceId": "i-00000038",
 "instanceState": "running",
 "description": "common node"
}

我需要使用multimatch查询来查询它。但是当我执行以下查询时:

{
   "query": {
      "multi_match" : {
         "query":    "172.31.8.12", 
         "fields": ["instanceId", "description", "privateIp", "publicIp"],
         "operator": "AND",
         "type": "cross_fields",
         "lenient": true
}}}

我找回了两个不受欢迎的文件 - 我只想要 doc1 。此外, doc2 的得分高于 doc1

publicIp privateIp 都会映射为IP类型。

我怎样才能找回doc1?

1 个答案:

答案 0 :(得分:0)

cross_fields 用于以术语为中心的匹配

默认情况下,分析器会将Ip的值分成多个部分,分隔点

你应该将Ip字段设置为未在映射中分析以匹配整个Ip