Elasticsearch dsl使用python嵌套过滤器

时间:2018-06-04 18:29:52

标签: python elasticsearch elasticsearch-dsl

我正在使用字符串q调用函数。我想过滤索引youtube并返回snippet.tags: ['q' , ...]的所有对象。

request = Search(using=client, index='youtube', doc_type='video') \
.filter('nested', path='snippet', query=Q('terms', snippet__tags=q))
response = request.execute()
return response

我得到的错误:

elasticsearch.exceptions.RequestError: TransportError(400, 'parsing_exception', '[terms] query does not support [snippet.tags]')

如何访问嵌套字段?数据如下所示:

{
  "_index": "youtube",
  "_type": "video",
  "_id": "4",
  "_version": 1,
  "_score": 2,
  "_source": {
    "snippet": {
      "publishedAt": "2012-02-18T11:18:13.000Z",
      "localized": {
        "description": "Trochę deskorolki.",
        "title": "BlackAndWhite"
      },
      "description": "Trochę deskorolki.",
      "title": "BlackAndWhite",
      "thumbnails": {
        "default": {
          "width": 120,
          "url": "https://i.ytimg.com/vi/-1z6vhzgAmA/default.jpg",
          "height": 90
        },
        "high": {
          "width": 480,
          "url": "https://i.ytimg.com/vi/-1z6vhzgAmA/hqdefault.jpg",
          "height": 360
        },
        "medium": {
          "width": 320,
          "url": "https://i.ytimg.com/vi/-1z6vhzgAmA/mqdefault.jpg",
          "height": 180
        }
      },
      "channelId": "UCpB21jldauE1dI-bLfm8JWA",
      "categoryId": "17",
      "channelTitle": "sk8robcio",
      "tags": [
        "skateboard",
        "deskorolka",
        "Skate",
        "Skateboarding",
        "Sk8",
        "Park",
        "Skating",
        "Board",
        "Skater",
        "Ollie",
        "brodnica"
      ],
      "liveBroadcastContent": "none"
    },
    "topicDetails": {
      "relevantTopicIds": [
        "/m/019_rr",
        "/m/019_rr"
      ],
      "topicCategories": [
        "https://en.wikipedia.org/wiki/Lifestyle_(sociology)"
      ]
    },
    "kind": "youtube#video",
    "etag": "\"m2yskBQFythfE4irbTIeOgYYfBU/kV2vSGw1ZJOLul1gHUQC4LEfaws\"",
    "id": "-1z6vhzgAmA",
    "status": {
      "license": "youtube",
      "privacyStatus": "public",
      "uploadStatus": "processed",
      "publicStatsViewable": true,
      "embeddable": true
    },
    "statistics": {
      "dislikeCount": "0",
      "likeCount": "12",
      "viewCount": "1286",
      "favoriteCount": "0",
      "commentCount": "5"
    },
    "player": {
      "embedHtml": "<iframe width=\"480\" height=\"270\" src=\"//www.youtube.com/embed/-1z6vhzgAmA\" frameborder=\"0\" allowfullscreen></iframe>"
    }
  }
}

0 个答案:

没有答案