Elasticsearch php client searching from multiple indices

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'],
                                    ]
                                ] */
                            ]
                        ]
                    ]
                ]
            ];

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).

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