# What is the alternative to TermFilter() in ElasticSearch 7.5

**URL:** <https://discuss.elastic.co/t/what-is-the-alternative-to-termfilter-in-elasticsearch-7-5/213068>\
**Category:** Elasticsearch\
**Created:** [December 26, 2019, 10:38am UTC](https://discuss.elastic.co/t/what-is-the-alternative-to-termfilter-in-elasticsearch-7-5/213068 "2019-12-26T10:38:22Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![elabedouss](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/elabedouss/32/79800_2.png) [@elabedouss](https://discuss.elastic.co/u/elabedouss)\
**Post date:** [December 26, 2019, 10:38am UTC](https://discuss.elastic.co/t/what-is-the-alternative-to-termfilter-in-elasticsearch-7-5/213068/1 "2019-12-26T10:38:22Z")

</div>

I am wondering about an alternative method to `TermFilter()` in ES 7.5, it's deprecated since ES 2.x. My current method:

```
     @Override
public boolean deleteAnnotation(String userName, String id) throws Exception {
    final IndexAndType annotationIndex = indexConfiguration.getIndex(Annotation);

    final SearchResponse searchResponse = esClient.prepareSearch(annotationIndex.getIndex()).setTypes(annotationIndex.getType()).setQuery(
            filteredQuery(QueryBuilders.termQuery(AnnotationField.id.field(), id), termFilter(AnnotationField.user.field(), userName))
    ).execute().actionGet();

    if (0 < searchResponse.getTotalShards()) {
        final SearchHit hit = searchResponse.getHits().getAt(0);

        final DeleteResponse deleteResponse = esClient.prepareDelete(annotationIndex.getIndex(), annotationIndex.getType(), hit.getId()).execute().actionGet();

        return deleteResponse.isFound();
    }

    return false;
}
```

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [January 23, 2020, 10:38am UTC](https://discuss.elastic.co/t/what-is-the-alternative-to-termfilter-in-elasticsearch-7-5/213068/2 "2020-01-23T10:38:25Z")

</div>

Closed on January 23, 2020, 10:38am UTC

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
