yajiv
yajiv

Reputation: 2941

Can one document come into two buckets?

In elastic search, I have list of documents. And each document contain field type(possible value for type is 1,2,3,4,5). Now I want to create two bucket

  1. one contain document with type field value as 1 and
  2. contain all the document(including type 1).

Is it possible in elastic search? If yes then how?

I search on internet but I did not find anything that is helpful.

Following is document structure:-

"_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
               }

Upvotes: 0

Views: 47

Answers (1)

MrSimple
MrSimple

Reputation: 599

I copied this request from a visualization that Kibana made, it should work just the same. I picked one of your integer fields, change it if you need something else.

{
  "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
            }
          }
        }
      }
    }
  }
}

Upvotes: 1

Related Questions