如何在一个请求中获取不同match_phrase的单独输出

如何在一个请求中获取不同match_phrase的单独输出

我能够运行下面的查询,该查询给出截至total二的响应match_phrase

插入虚拟数据如下。

POST /mod1/_bulk
{ "index" : { } }
{ "msg": "BA1" }
{ "index" : { } }
{ "msg": "BA2" }
{ "index" : { } }
{ "msg": "BA2" }
{ "index" : { } }
{ "msg": "BA1" }
{ "index" : { } }
{ "msg": "BA2" }
{ "index" : { } }
{ "msg": "BA1" }
{ "index" : { } }
{ "msg": "BA1" }
{ "index" : { } }

Request-

GET mod1/_search
{
  "size": 0,
  "query": {
    "bool": {
    "should": [
        {
          "match_phrase": {
            "msg": "BA1"
          }
        },
        {
          "match_phrase": {
            "msg": "BA2"
          }
        }
      ]
    }
  }
}

Response-

{
  "took" : 0,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 7,
      "relation" : "eq"
    },
    "max_score" : null,
    "hits" : [ ]
  }
}

得到的响应是7,因为BA14BA23,所以给出两个的总和match_phrase,我如何才能得到如下所示的响应,即两个的单独输出match_phrase

.
.
"BA1"
"hits" : {
    "total" : {
      "value" : 4,

.
.
"BA2"
"hits" : {
    "total" : {
      "value" : 3,

谢谢,

相关内容