Elasticsearch嵌套查询和过滤器

时间:2014-09-02 07:00:30

标签: elasticsearch

我有以下Elasticsearch映射:

"show": {
  "properties": {
    "startsAt": {
      "type": "date"
    },
    "venue": {
      "type": "nested",
      "properties": {
        "name": {
          "type": "string"
        },
        "address": {
          "type": "string",
          "index": "no"
        },
        "location": {
          "type": "geo_point",
          "lat_lon": true
        },
        "section": {
          "type": "string",
          "index": "not_analyzed"
        }
      }
    }
  }
}

我希望使用show.startsAtshow.venue.locationshow.venue.section属性找到完全匹配。我一直在尝试以下查询,但它没有考虑show.venue.section

bool: {
  must: [
    {match: {startsAt: starts}},
    {
      nested: {
        path: 'venue',
        query: {
          match: {'venue.section': section}
        },
        filter: {
          geo_distance: {
            distance: '1m',
            'venue.location': location
          }
        }
      }
    }
  ]
}

1 个答案:

答案 0 :(得分:0)

此查询对我有用:

  query: {
    bool: {
      must: [
        {match: {startsAt: starts}},
        {
          nested: {
            path: 'venue',
            filter: {
              bool: {
                must: [
                  {
                    geo_distance: {
                      distance: '1m',
                      'venue.location': location
                    }
                  },
                  {
                    term: {'venue.section': section}
                  }
                ]
              }
            }
          }
        }
      ]
    }
  }