# What is the alternative way of querying \_all from elasticsearch 6.x onwards?

**URL:** <https://discuss.elastic.co/t/what-is-the-alternative-way-of-querying-all-from-elasticsearch-6-x-onwards/228749>\
**Category:** Elasticsearch\
**Created:** [April 19, 2020, 5:30pm UTC](https://discuss.elastic.co/t/what-is-the-alternative-way-of-querying-all-from-elasticsearch-6-x-onwards/228749 "2020-04-19T17:30:59Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Deb](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/deb/32/46162_2.png) [@Deb](https://discuss.elastic.co/u/Deb)\
**Post date:** [April 19, 2020, 5:30pm UTC](https://discuss.elastic.co/t/what-is-the-alternative-way-of-querying-all-from-elasticsearch-6-x-onwards/228749/1 "2020-04-19T17:30:59Z")

</div>

I posted the same in [stackoverflow](https://stackoverflow.com/questions/58776241/what-is-the-alternative-way-of-querying-all-from-elasticsearch-6-x-onwards) but did not get any reply. Just posting the same here in case someone has any suggestions.

As mentioned in the [doc](https://www.elastic.co/guide/en/elasticsearch/reference/6.7/mapping-all-field.html), from elasticsearch 6.x `_all` has been deprecated. I have a `matchQuery` like below

```auto
QueryBuilders.boolQuery()
                        .should(QueryBuilders.matchQuery("_all", typeAndName.name))
                        .should(buildMatchQuery(
                                SearchFields.kObjectNameKey,
                                dataModel.getLowerFieldName(PropertyType.STRING, SearchFields.kObjectNameKey),
                                typeAndName.name));

```

Can someone suggest what is the recommended way of doing the same now?

In my case, I don't know beforehand what all fields can be there in the index so I cannot use `copy_to` in index mapping to copy all fields data to some other field to simulate all.

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [April 19, 2020, 5:36pm UTC](https://discuss.elastic.co/t/what-is-the-alternative-way-of-querying-all-from-elasticsearch-6-x-onwards/228749/2 "2020-04-19T17:36:40Z")

</div>

Have a look at the [copy to](https://www.elastic.co/guide/en/elasticsearch/reference/6.8/copy-to.html) functionality.

---

<div class="post-metadata">

**Author:** ![Deb](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/deb/32/46162_2.png) [@Deb](https://discuss.elastic.co/u/Deb)\
**Post date:** [April 19, 2020, 5:53pm UTC](https://discuss.elastic.co/t/what-is-the-alternative-way-of-querying-all-from-elasticsearch-6-x-onwards/228749/3 "2020-04-19T17:53:05Z")

</div>

@Christian_Dahlqvist - As posted above, in my case, I don't know beforehand what all fields can be there in the index so I cannot use `copy_to` in index mapping to copy all fields data to some other field to simulate all.

Maybe I am missing something.

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [April 19, 2020, 5:59pm UTC](https://discuss.elastic.co/t/what-is-the-alternative-way-of-querying-all-from-elasticsearch-6-x-onwards/228749/4 "2020-04-19T17:59:49Z")

</div>

You should be able to specify it for dynamic mappings through an index template.

---

<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:** [May 17, 2020, 5:59pm UTC](https://discuss.elastic.co/t/what-is-the-alternative-way-of-querying-all-from-elasticsearch-6-x-onwards/228749/5 "2020-05-17T17:59:50Z")

</div>

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