bala n
bala n

Reputation: 39

How to create the new index based on aggregation in elasticsearch

 POST /_reindex?wait_for_completion=false //reindexing
    {
      "source": {
        "index": "as.event-154",
        "aggs": {
        "group": {
          "terms": {
            "field": "ancestor_id",
            "size": 1 // note this
          },
          "aggs": {
            "group_docs": {
              "top_hits": {
                "size": 10,
                 "_source": false,
                "sort": [
                  {
                    "event_id.keyword": {
                      "order": "desc"
                    }
                  }
                ]
              }
            }
          }
        },
        "bucketcount": {
          "stats_bucket": {
            "buckets_path": "group._count"
          }
        }
      }
      },
       "dest": {
        "index": "as.event-154new1"
      }}

This is my elastic query to create the new index based on the aggregation filter. It creates a new index with all data. but I need only the specific conditions data. Please help to fix these issues

Upvotes: 0

Views: 49

Answers (1)

Musab Dogan
Musab Dogan

Reputation: 3660

You can add query parameter in source.

POST /_reindex
{
  "source": {
    "index": "test",
    "query": {...}, <---
    "aggs": {..}
  },
  "dest": {...}
}

Ref: https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-reindex.html#docs-reindex-select-query

Upvotes: 1

Related Questions