# Is there an easy way that can search specify indices, if not, search all?

**URL:** <https://discuss.elastic.co/t/is-there-an-easy-way-that-can-search-specify-indices-if-not-search-all/193023>\
**Category:** Elasticsearch\
**Created:** [July 31, 2019, 3:22am UTC](https://discuss.elastic.co/t/is-there-an-easy-way-that-can-search-specify-indices-if-not-search-all/193023 "2019-07-31T03:22:26Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![imqishi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/imqishi/32/23426_2.png) [@imqishi](https://discuss.elastic.co/u/imqishi)\
**Post date:** [July 31, 2019, 3:22am UTC](https://discuss.elastic.co/t/is-there-an-easy-way-that-can-search-specify-indices-if-not-search-all/193023/1 "2019-07-31T03:22:26Z")

</div>

Now I have many data and indices, and search is slower, but most data can be searched in a year's indices(I split data by month), so I want to search latest 1 year first, if not get result, try to search all.

I can do this by two request, but I want to know if there's a way to do this once, for example, can I point exact indices first and append \* at last, like this: [http://ip](http://ip):port/index1,index2,index3,index\*/\_search  
if limit 1, will this find by sequence and when it find stop other search?

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [August 1, 2019, 12:57pm UTC](https://discuss.elastic.co/t/is-there-an-easy-way-that-can-search-specify-indices-if-not-search-all/193023/2 "2019-08-01T12:57:33Z")

</div>

Hey,

there is an early termination feature, see here [https://www.elastic.co/guide/en/elasticsearch/client/java-api/7.2/java-search-terminate-after.html](https://www.elastic.co/guide/en/elasticsearch/client/java-api/7.2/java-search-terminate-after.html)

However this still would query each shard that is involved.

Are you searching for documents or aggregating only?

--Alex

---

<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:** [August 29, 2019, 12:57pm UTC](https://discuss.elastic.co/t/is-there-an-easy-way-that-can-search-specify-indices-if-not-search-all/193023/3 "2019-08-29T12:57:34Z")

</div>

Closed on August 29, 2019, 12:57pm UTC

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