Elasticsearch必须在列表对象上

时间:2018-05-30 10:04:15

标签: elasticsearch nest elasticsearch-5 elasticsearch-net

我使用的是Elastic 6.0。我的kibana查询如下

!preg_match("/^(?:[\w\d-]+\.?)+@(?:(?:[\w\d]\-?)+\.)+\w{2,4}$/", $email)

给我结果

  "bool": {
       "must": [
          {
           "match": {
             "relationships.relation": {
               "query": "spouse"
            }
      }
    },
    {
      "match": {
        "relationships.first_name": {
          "query": "james"
        }
      }
    },
    {
      "match": {
        "relationships.last_name": {
          "query": "smith"
        }
      }
    }
  ]
}

我只想获得第一个结果,因为它包含基于我的查询的完全匹配              {                 " first_name":" James S。",                  " last_name":" Smith",                 "关系":"配偶"               }   我已经尝试了术语查询,但它给出了与上面相同的结果。任何建议   会有很大的帮助。

1 个答案:

答案 0 :(得分:1)

这听起来好像relationships映射为object type。为了使其按预期工作,relationships需要映射为nested type,您应该使用nested queries来查询嵌套对象的字段。