0

I have an elastic query aggregation in which I need to filter aggregation on the basis on index name. Query section actually working on multiple indexes, but I want to filter aggregation for particular index. Please help me how we can pass index filter in aggregation -

{       
    "query": {
        "bool": {
            "filter": [
                {
                    "bool": {
                        "should": [
                            {
                                "query_string": {
                                    "fields": [
                                        "productDesc",
                                        "productDescription"
                                    ],
                                    "default_operator": "AND",
                                    "query": "machine"
                                }
                            }
                        ]
                    }
                }
            ],
            "must": [ ],
            "must_not": [ ]
        }
    },
    "size": 0,
    "aggs": {
        "RelatedKeywords": { //here I want to add filter of index
            "sampler": {
                "shard_size": 20
            },
            "aggregations": {
                "keywords": {
                    "significant_text": {
                        "field": "productDesc",
                        "size": 100,
                        "filter_duplicate_text": true
                    }
                }
            }
        }
    }
}

1 Answer 1

1

You can do it like this:

{
  "aggs": {
    "index": {
      "filter": {
        "term": {
          "_index": "index-name"
        }
      },
      "aggs": {
        "RelatedKeywords": {
          "sampler": {
            "shard_size": 20
          },
          "aggregations": {
            "keywords": {
              "significant_text": {
                "field": "productDesc",
                "size": 100,
                "filter_duplicate_text": true
              }
            }
          }
        }
      }
    }
  }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.