# Index from multi indexes with elasticsearch-PHP

**URL:** <https://discuss.elastic.co/t/index-from-multi-indexes-with-elasticsearch-php/176712>\
**Category:** Elasticsearch\
**Created:** [April 13, 2019, 1:38am UTC](https://discuss.elastic.co/t/index-from-multi-indexes-with-elasticsearch-php/176712 "2019-04-13T01:38:16Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![evahsiao](https://avatars.discourse-cdn.com/v4/letter/e/d26b3c/32.png) [@evahsiao](https://discuss.elastic.co/u/evahsiao)\
**Post date:** [April 13, 2019, 1:38am UTC](https://discuss.elastic.co/t/index-from-multi-indexes-with-elasticsearch-php/176712/1 "2019-04-13T01:38:16Z")

</div>

here is my problem:  
I have many messages data in elasticsearch db, these data are stored in the same type but different index according to the date. for example, all the messages today are stored in the message\_2019-04-13 index. now i want to search all the messages sent by someone with elasticsearch-PHP:

```
$arr = [
    'index' => 'messages_*',
    'type' => 'doc',
    'body' => [
        'query' => [
             'bool' => [
                 'must' => [
                      ['match' => ['from_user_id' => 1]],
                      ['match' => ['from_user_type' => 'admin']],
                 ],
             ],
         ]
     ]
];
$clientBuilder = ClientBuilder::create();
$clientBuilder->setHosts('127.0.0.1');
$clientBuilder->setRetries(3);
$client = $clientBuilder->build();
$res = $client->search($arr);

```

But it doesnt work, how can i do?

---

<div class="post-metadata">

**Author:** ![evahsiao](https://avatars.discourse-cdn.com/v4/letter/e/d26b3c/32.png) [@evahsiao](https://discuss.elastic.co/u/evahsiao)\
**Post date:** [April 13, 2019, 3:36am UTC](https://discuss.elastic.co/t/index-from-multi-indexes-with-elasticsearch-php/176712/2 "2019-04-13T03:36:24Z")

</div>

i have read the api document and find a solution:  
1.use the get mappings api to get the index list

```
$params = [
    'index' => 'messages_*',
    'type' => 'doc'
];
$response = $client->indices()->getMapping($params);

```

2.loop the index list and get the documents by the same search fields condition.  
that means i have to run two circulations to gain the result. If the one i want to search have no messages in the first 10 days, i still have to search the index list from the first day. Is there a more efficient solution?

---

<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 11, 2019, 3:36am UTC](https://discuss.elastic.co/t/index-from-multi-indexes-with-elasticsearch-php/176712/3 "2019-05-11T03:36:24Z")

</div>

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