2014-09-02 118 views
0

我有以下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 
      } 
     } 
     } 
    } 
    ] 
} 

回答

0

這個查詢工作對我來說:

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