Elasticsearch如何查询映射为对象的字段

时间:2015-10-11 08:21:19

标签: indexing elasticsearch

我有一些索引到elasticsearch的文档。文档结构如下。

{
    "body": {
        "gnip": {
            "matching_rules": [
                {
                    "tag": "NationalIssues90"
                }
            ],
            "urls": [
                {
                    "url": "http://t.co/CKqZeXPLqK"
                }
            ]
        },
        "body": "RT @fayez_malki: يطلب الله ثم يطلب #الأمير_محمد_بن_سلمان ومنا الي الشهم #المطنوخ_محمد بن سلمان http://t.co/CKqZeXPLqK",
        "postedTime": "2015-10-11T07:53:20.000Z",
        "provider": {
            "link": "http://www.twitter.com",
            "displayName": "Twitter",
            "objectType": "service"
        },
        "twitter_entities": {
            "hashtags": [
                {
                    "text": "المطنوخ_محمد"
                }
            ],
            "media": [
                {
                    "media_url_https": "https://pbs.twimg.com/ext_tw_video_thumb/652619994493284352/pu/img/awivyn9cnau285PQ.jpg",
                    "media_url": "http://pbs.twimg.com/ext_tw_video_thumb/652619994493284352/pu/img/awivyn9cnau285PQ.jpg",
                }
            ]
        },
        "id": "tag:search.twitter.com,2005:653116156212064257",
        "verb": "share",
    },
    "collection": "NationalIssues"
}

在json的末尾有一个名为twitter_entities的字段。该字段的映射如下

{
    "twitter_entities": {
        "type": "object",
        "dynamic": "strict",
        "properties": {
            "hashtags": {
                "type": "object",
                "dynamic": "strict",
                "properties": {
                    "indices": {
                        "type": "long",
                        "index": "no",
                        "store": false
                    },
                    "text": {
                        "type": "string",
                        "index": "analyzed",
                        "store": true
                    }
                }
            },
            "media": {
                "type": "object",
                "dynamic": "strict",
                "properties": {
                    "media_url": {
                        "type": "string",
                        "index": "analyzed",
                        "store": true
                    },
                    "media_url_https": {
                        "type": "string",
                        "index": "analyzed",
                        "store": true
                    }
                }
            }
        }
    }
}

我正在尝试获取包含media_url字段中的值的所有文档。换句话说,我想获取media_url字段不为空的所有文档。我使用了以下查询,但所有查询都返回空值,而我确信这个字段中有很多文档都有值。

{
  "query": {
    "match": {
      "body.twitter_entities.media.media_url": {
        "query": "http*",
        "operator": "AND"
      }
    }
  }
}

这是另一次尝试,但没有任何运气

{
    "query" : {
        "term" : { "body.twitter_entities.media.media_url" : "http*" }
    }
}

我也尝试了以下查询,结果是一样的。

{
    "query": {
        "bool": {
            "must": [

                {
                    "query_string": {
                        "fields": [
                            "body.twitter_entities.media.media_url"
                        ],
                        "query": "*",
                        "use_dis_max": true
                    }
                }

            ]
        }
    }
}

我怀疑地图,但我不确定问题出在哪里。

0 个答案:

没有答案