arrays - ElasticSearch读取数组上的元素

标签 arrays indexing elasticsearch

我正在使用Elasticsearch,目前我有这样的结构

{
    "took": 2,
    "timed_out": false,
    "_shards": {
        "total": 1,
        "successful": 1,
        "failed": 0
    },
    "hits": {
        "total": 1,
        "max_score": 1,
        "hits": [
            {
                "_index": "999999",
                "_type": "content",
                "_id": "NmYTku",
                "_score": 1,
                "_source": {
                    "internal_id": "NmYTk4",
                    "external_id": "Ga_UI502",
                    "
                    "images": [
                        {
                            "uri_id": "2939306",
                            "url": "14mast_head.jpg",
                            "type": "Masthead",
                            "orientation": "Landscape",
                            "x_resolution": 3280,
                            "y_resolution": 1480
                        },
                        {
                            "uri_id": "Galavision/POST_poster/2939306",
                            "url": "140603_29un_erro_poster.jpg",
                            "type": "Poster",
                            "orientation": "Portrait",
                            "x_resolution": 720,
                            "y_resolution": 405
                        },
                        {
                            "uri_id": "Galavision/POST_poster_title/2939306",
                            "url": "140603_29un_erro_poster_title.jpg",
                            "type": "PosterWithTitle",
                            "orientation": "Portrait",
                            "x_resolution": 924,
                            "y_resolution": 518
                        },
                        {
                            "uri_id": "Galavision/POST_poster_cover/2939306",
                            "url": "140603_29poster_cover.jpg",
                            "type": "Poster",
                            "orientation": "Landscape",
                            "x_resolution": 600,
                            "y_resolution": 868
                        }
                    ]
                }
            }
        ]
    }
}

我想知道如何从数组中仅获取一个值,例如
我只希望在“风景”上具有定向的图像,然后键入Poster。我尝试使用此查询,但仅返回所有图像元素。
{
    "query": {
        "filtered": {
            "filter": { "term":{"_id":"NmYTku"} }
    }
},
  "_source": ["images"]
}

我不知道如何对元素进行过滤

最佳答案

您是否为图像使用嵌套字段或子字段?如果没有,该文档实际上将被索引为:

...
images.uri_id = [1, 2, 3, 4, etc..]
images.url = [1, 2, 3, 4, etc..]
images.type = [1, 2, 3, 4, etc..]
...

因此各个元素之间的区别消失了。尝试阅读以下内容:
http://www.elasticsearch.org/guide/en/elasticsearch/guide/current/complex-core-fields.html

如果您不需要查询,为什么不过滤掉您喜欢的客户端呢?

关于arrays - ElasticSearch读取数组上的元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24638071/

相关文章:

sql - PostgreSQL 中的 Gist 索引仅适用于顺序,但不适用于谓词

c - C 语言中字符数组的工作原理

检查数组是否包含 C 中另一个数组的所有数组值

C编程动态初始化二维数组

Mysql 索引不适用于单个 Group By

elasticsearch - 本地 Elasticsearch 存储清除

java - 将数组元素传递给接受整数的方法 (Java)

MySQL 全文搜索 : fulltext and INT columns in the same query

elasticsearch - 聚合对ElasticSearch跨集群搜索的性能

elasticsearch - Elasticsearch-添加节点而不复制吗?