# Elasticsearch php client searching from multiple indices

**URL:** <https://discuss.elastic.co/t/elasticsearch-php-client-searching-from-multiple-indices/122043>\
**Category:** Elasticsearch\
**Created:** [March 1, 2018, 11:29am UTC](https://discuss.elastic.co/t/elasticsearch-php-client-searching-from-multiple-indices/122043 "2018-03-01T11:29:09Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Balog\_Dominik](https://avatars.discourse-cdn.com/v4/letter/b/85f322/32.png) [@Balog\_Dominik](https://discuss.elastic.co/u/Balog_Dominik)\
**Post date:** [March 1, 2018, 11:29am UTC](https://discuss.elastic.co/t/elasticsearch-php-client-searching-from-multiple-indices/122043/1 "2018-03-01T11:29:09Z")

</div>

How can I specify query rules for each index when searching through multiple indices?  
Because indexed the same table twice with different mappings. But I need different query rules for each index when i'm searching.

```
    $params = [
                'index' => 'serviceme,serviceme_ngram',
                'type' => 'products,products',
                'size' => $size,
                'body' => [
                    'query' => [
                        "bool" => [
                            'should' => [
                                [
                                    'match' => [
                                        'product_number' => [
                                            'query' => $query,
                                        ]
                                    ]
                                ],
                                [
                                    'match' => [
                                        'producer_name' => [
                                            'query' => $query,
                                        ]
                                    ]
                                ],
                                [
                                    'match' => [
                                        'product_name' => [
                                            'query' => $query,
                                        ]
                                    ]
                                ],
                                [
                                    'match' => [
                                        'producer_name' => [
                                            'query' => $query,
                                            'fuzziness' => 'AUTO'
                                        ]
                                    ]
                                ],
                                [
                                    'match' => [
                                        'product_name' => [
                                            'query' => $query,
                                            'fuzziness' => 'AUTO'
                                        ]
                                    ]
                                ]
                                /* [
                                    'multi_match' => [
                                        'query' => $query,
                                        'fuzziness' => 'AUTO',
                                        "prefix_length" => 0,
                                        "max_expansions" => 100,
                                        'fields' => ['product_number', 'product_name', 'producer_name'],
                                    ]
                                ] */
                            ]
                        ]
                    ]
                ]
            ];
```

---

<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:** [March 1, 2018, 2:55pm UTC](https://discuss.elastic.co/t/elasticsearch-php-client-searching-from-multiple-indices/122043/2 "2018-03-01T14:55:27Z")

</div>

You could use a `bool` query with 2 `should` clauses:

The first will be a bool query again with a filter clause containing a `term` query on `_index` field for `serviceme` and a `must` clause with the query you pasted.

The second will be a bool query again with a filter clause containing a `term` query on `_index` field for `serviceme_ngram` and a `must` clause with the query you pasted (including the `multi_match` part).

---

<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 29, 2018, 2:55pm UTC](https://discuss.elastic.co/t/elasticsearch-php-client-searching-from-multiple-indices/122043/3 "2018-03-29T14:55:45Z")

</div>

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