一份文件能分到两个桶里吗?

Can one document come into two buckets?

在弹性搜索中,我有文档列表。每个文档都包含字段类型(类型的可能值为 1、2、3、4、5)。现在我想创建两个桶

  1. 一个包含类型字段值为 1 和
  2. 的文档
  3. 包含所有文档(包括类型 1)。

在弹性搜索中可以吗?如果是那么怎么办?

我在互联网上搜索,但没有找到任何有用的信息。

文档结构如下:-

"_source": { "city": "Ahmadabad",
               "pId": "A1332605",
               "sellerType": 1,
               "seller": "Dealer",
               "makeId": 7,
               "makeName": "ABC",
               "modelId": 673,
               "type": 1
           },
"_source": { "city": "Surat",
                   "pId": "A265843",
                   "sellerType": 1,
                   "seller": "Dealer",
                   "makeId": 45,
                   "makeName": "XYZ",
                   "modelId": 520,
                   "type": 2
               }

我从 Kibana 制作的可视化中复制了这个请求,它应该可以正常工作。我选择了您的一个整数字段,如果您需要其他字段,请更改它。

{
  "query": {
    // your query
  },
  "size": 0,
  "_source": {
    "excludes": []
  },
  "aggs": {
    "2": {
      "filters": {
        "filters": {
          "filter_for_specific": {
            "query_string": {
              "query": "sellerType: 1",
              "analyze_wildcard": true
            }
          },
          "filter_for_existing": {
            "query_string": {
              "query": "sellerType: *",
              "analyze_wildcard": true
            }
          }
        }
      }
    }
  }
}