1

我的索引元数据:

{
   "never": {
      "aliases": {},
      "mappings": {
         "userDetails": {
            "properties": {
               "Residence_address": {
                  "type": "nested",
                  "include_in_parent": true,
                  "properties": {
                     "Address_type": {
                        "type": "string",
                        "analyzer": "standard"
                     },
                     "Pincode": {
                        "type": "string",
                        "analyzer": "standard"
                     },
                     "address": {
                        "type": "string",
                        "analyzer": "standard"
                     }
                  }
               }
            }
         }
      },
      "settings": {
         "index": {
            "creation_date": "1468850158519",
            "number_of_shards": "5",
            "number_of_replicas": "1",
            "version": {
               "created": "1060099"
            },
            "uuid": "v2njuC2-QwSau4DiwzfQ-g"
         }
      },
      "warmers": {}
   }
}

我的设置:

POST never 

{
   "settings": {
        "number_of_shards" : 5,
      "analysis": {
         "analyzer": {
            "standard": {
               "tokenizer": "keyword",
               "filter" : ["lowercase","reverse"]
            }
         }
      }
   }
}

我的数据:

{
   "took": 1,
   "timed_out": false,
   "_shards": {
      "total": 5,
      "successful": 5,
      "failed": 0
   },
   "hits": {
      "total": 1,
      "max_score": 0.375,
      "hits": [
         {
            "_index": "never",
            "_type": "userDetails",
            "_id": "1",
            "_score": 0.375,
            "_source": {
               "Residence_address": [
                  {
                     "address": "Omega Residency",
                     "Address_type": "Owned",
                     "Pincode": "500004"
                  },
                  {
                     "address": "Collage of Engineering",
                     "Address_type": "Rented",
                     "Pincode": "411005"
                  }
               ]
            }
         }
      ]
   }
}

我的查询:

POST /never/_search?pretty
{
   "query": {
         "match": {
                "Residence_address.address": "Omega"
            }
         }
      }

我的结果:

{
   "took": 1,
   "timed_out": false,
   "_shards": {
      "total": 5,
      "successful": 5,
      "failed": 0
   },
   "hits": {
      "total": 1,
      "max_score": 0.375,
      "hits": [
         {
            "_index": "never",
            "_type": "userDetails",
            "_id": "1",
            "_score": 0.375,
            "_source": {
               "Residence_address": [
                  {
                     "address": "Omega Residency",
                     "Address_type": "Owned",
                     "Pincode": "500004"
                  },
                  {
                     "address": "Collage of Engineering",
                     "Address_type": "Rented",
                     "Pincode": "411005"
                  }
               ]
            }
         }
      ]
   }
}

有没有办法将我的结果限制为仅包含地址 = Omega Residency 的对象,而不是其他具有地址 = 工程拼贴的对象?

4

1 回答 1

1

您只能使用nestedquery 和inner_hits. 我看到你有include_in_parent: true并且没有使用nested查询。如果您只想inner_hitsnested查询中获取需要使用的匹配嵌套对象:

GET /never/_search?pretty
{
  "_source": false, 
  "query": {
    "nested": {
      "path": "Residence_address",
      "query": {
        "match": {
          "Residence_address.address": "Omega Residency"
        }
      },
      "inner_hits" : {}
    }
  }
}
于 2016-07-18T16:16:29.577 回答