首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ElasticSearch聚合丢失数据

ElasticSearch聚合丢失数据
EN

Stack Overflow用户
提问于 2015-04-04 14:56:22
回答 1查看 1.2K关注 0票数 1

在弹性搜索中,当我运行聚合查询时,它只在一个索引上运行它。我怎样才能让它在多个起诉中运行?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-04-04 16:24:09

做一个多索引搜索

例如,我通过批量索引一些数据创建了几个索引(隐式):

代码语言:javascript
复制
POST /_bulk
{ "index": {"_index": "test_index", "_type":"doc"}}
{ "name": "Brown foxes"}
{ "index": {"_index": "test_index_2", "_type":"doc"}}
{ "name": "Yellow furballs" }
{ "index": {"_index": "test_index", "_type":"doc"}}
{ "name": "my discovery" }
{ "index": {"_index": "test_index_2", "_type":"doc"}}
{ "name": "myself is fun" }
{ "index": {"_index": "test_index", "_type":"doc"}}
{ "name": ["foxy", "foo"]    }
{ "index": {"_index": "test_index_2", "_type":"doc"}}
{ "name": ["foo bar", "baz"] }

然后,我可以在这两个索引上运行聚合:

代码语言:javascript
复制
POST /test_index,test_index_2/_search?search_type=count
{
    "aggs": {
        "name_terms": {
            "terms": {
                "field": "name"
            }
        }
    }
}

我从两个人那里得到了所有的条件:

代码语言:javascript
复制
{
   "took": 2,
   "timed_out": false,
   "_shards": {
      "total": 10,
      "successful": 10,
      "failed": 0
   },
   "hits": {
      "total": 6,
      "max_score": 0,
      "hits": []
   },
   "aggregations": {
      "name_terms": {
         "buckets": [
            {
               "key": "foo",
               "doc_count": 2
            },
            {
               "key": "bar",
               "doc_count": 1
            },
            {
               "key": "baz",
               "doc_count": 1
            },
            {
               "key": "brown",
               "doc_count": 1
            },
            {
               "key": "discovery",
               "doc_count": 1
            },
            {
               "key": "foxes",
               "doc_count": 1
            },
            {
               "key": "foxy",
               "doc_count": 1
            },
            {
               "key": "fun",
               "doc_count": 1
            },
            {
               "key": "furballs",
               "doc_count": 1
            },
            {
               "key": "is",
               "doc_count": 1
            }
         ]
      }
   }
}

下面是代码:

http://sense.qbox.io/gist/e053a0c6c5453eae68d7b7ff2ff12588669b046e

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/29447836

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档