如何在显示elasticsearch结果时将_index和_type分组到_source的父级

时间:2018-04-24 22:34:36

标签: elasticsearch

假设我需要查询多个索引和doc,如下所示 我想将_source元素分组到它们自己的_index,_type作为父元素,但不知何故它给出了每个索引,在每个块中键入,我很难管理结果

GET /index_1,index_2,hockey,bookdb_index/_search?size=200

        {
        "_index": "hockey",
        "_type": "player",
        "_id": "10",
        "_score": 1,
        "_source": {
            "first": "mikael",
            "last": "backlund",
            "goals": [
                3,
                15,
                13
            ],
            ...
        }
    },
    {
        "_index": "bookdb_index",
        "_type": "book",
        "_id": "2",
        "_score": 1,
        "_source": {
            "title": "Taming Text:...
        }
    },

如何将索引和类型分组为父级,_source是子元素

"hockey": {
    "player": [{
       "first": "mikael",
        "last": "backlund",
        "goals": [
            3,
            15,
            13
        ] }
      }, { "first": ...

      }]
}, 
"bookdb_index": { ...

1 个答案:

答案 0 :(得分:0)

我为此创建了客户端等等。

Nginx Elastic Client

纯弹性搜索在nginx.conf中编写,弹性服务器上游, 您可以选择index_docs来获得所需的结果。有关详细信息,请参阅自述文件。

 location /test {
    elastic_pass http://elastic_upstream;
    elastic_send POST /testindex/testdoc/_search?size=100 index_docs;

    elastic_query '{"query":
       {
        "match_all": {}
       }
    }';
 }