簡體   English   中英

Elasticsearch嵌套查詢和過濾器

[英]Elasticsearch nested query and filter

我有以下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.startsAt 我一直在嘗試下面的查詢,但沒有考慮show.venue.section

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

這個查詢對我有用:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM