# How to use Index pattern using REST API

**URL:** <https://discuss.elastic.co/t/how-to-use-index-pattern-using-rest-api/168978>\
**Category:** Elasticsearch\
**Created:** [February 19, 2019, 9:28am UTC](https://discuss.elastic.co/t/how-to-use-index-pattern-using-rest-api/168978 "2019-02-19T09:28:27Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![smidev11](https://avatars.discourse-cdn.com/v4/letter/s/b9bd4f/32.png) [@smidev11](https://discuss.elastic.co/u/smidev11)\
**Post date:** [February 19, 2019, 9:28am UTC](https://discuss.elastic.co/t/how-to-use-index-pattern-using-rest-api/168978/1 "2019-02-19T09:28:27Z")

</div>

Hi All,

How to use Index pattern to search from multiple tables using low level rest client api.

E.g , Lets assume I have following index names as:

1. Index\_2019\_1
2. Index\_2019\_2
3. Index\_2018\_1
4. index\_2018\_2

Now I want get data from Index\_2019\_\* ( Index\_2019\_1 and Index\_2019\_2) using Java api,

I am new to ES and not sure how to use GET API to achieve this.

Please provide me some pointer or sample example would be of great help.

---

<div class="post-metadata">

**Author:** ![Josef\_Fritzer](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/josef_fritzer/32/54420_2.png) [@Josef\_Fritzer](https://discuss.elastic.co/u/Josef_Fritzer)\
**Post date:** [February 19, 2019, 9:46am UTC](https://discuss.elastic.co/t/how-to-use-index-pattern-using-rest-api/168978/2 "2019-02-19T09:46:48Z")

</div>

What I know so far is, that you can search over multiple indices:

`SearchRequest searchRequest = new SearchRequest(INDEX, INDEX2)`

but I think that "index pattern names" are not supported, so you have to write a logic on your own. But you can give Index\_2019\_1 and Index\_2019\_2 the same **type** when creating them e.g. " **Index\_2019**" and than you can try searching over index types. That could work, hopefully.

`SearchRequest searchRequest = new SearchRequest(TYPE);`

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [February 19, 2019, 9:48am UTC](https://discuss.elastic.co/t/how-to-use-index-pattern-using-rest-api/168978/3 "2019-02-19T09:48:04Z")

</div>

```auto
SearchRequest searchRequest = new SearchRequest("Index_2019_*")

```

Should work AFAIK.

But note that is for the **Search** API not the **GET** API.

---

<div class="post-metadata">

**Author:** ![smidev11](https://avatars.discourse-cdn.com/v4/letter/s/b9bd4f/32.png) [@smidev11](https://discuss.elastic.co/u/smidev11)\
**Post date:** [February 21, 2019, 5:34am UTC](https://discuss.elastic.co/t/how-to-use-index-pattern-using-rest-api/168978/4 "2019-02-21T05:34:12Z")

</div>

> [@dadoonet](#):
>
> But note that is for the **Search** API not the **GET** A

Thanks for Reply,

BTW, I found that Index\_2019\_\* is also working for GET API.  
i.e [http://host](http://host):port/index\_\*/doc/\_search

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [February 21, 2019, 5:57am UTC](https://discuss.elastic.co/t/how-to-use-index-pattern-using-rest-api/168978/5 "2019-02-21T05:57:41Z")

</div>

This is a search API call using a GET HHTP verb.  
Not the GET DocumenAPI.

---

<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:** [March 21, 2019, 5:57am UTC](https://discuss.elastic.co/t/how-to-use-index-pattern-using-rest-api/168978/6 "2019-03-21T05:57:47Z")

</div>

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