0

I have an elasticsearch that is working fine and so is my php client used to query the index. However, my client works only with one index. When I try adding multiple indices in a string as shown here my code breaks.

Here is a snippet of my code:

           if ($q2 == '') {
                $query = $client->search([
                    'index' => 'trial2',
                    'body' => [
                        'from' => $from,
                        'size' => $size,
                        'query' => [
                            'multi_match' => [
                                'query' => $q,
                                'operator' => $op,
                                'fields' => ['content','file','file.extension','meta', 'path']
                            ]
                        ]
                     ]
                 ]);

                 $data['q'] = $q;
            }

            elseif ($q2 == "docx") {
                $params = [
                    'index' => 'trial2',
                    'type' => '_doc',
                    'body' => [
                        'query' => [
                            'bool' => [
                                'must' => [
                                    [ 'terms' => [ 'file.extension' => ["docx", "doc", "txt", "rtf"] ] ],
                                    [ 'match' => [ 'content' => $q ] ],
                                ]
                            ]
                        ]
                    ]
                ];

                $query = $client->search($params);
                $data['q'] = $q;
            }

I would like to query several indexes (trial2, trial3 and trial4). How do I do it?

Denn
  • 447
  • 1
  • 6
  • 27
  • Does this answer your question? [Using multiple types or indexes in Elasticsearch php API](https://stackoverflow.com/questions/27021693/using-multiple-types-or-indexes-in-elasticsearch-php-api) – Jeto Oct 05 '20 at 05:22
  • I referred to that link in my question saying I've tried it but it breaks my code. – Denn Oct 05 '20 at 05:29
  • Sorry missed the link. Did you see that "it is VERY important you do not have a space after the comma in index value! It'll just crash it" comment? What do you mean by "breaks your code"? – Jeto Oct 05 '20 at 05:30
  • 1
    @Jeto Thank you. You made me review that question and saw that comment. Now it works perfectly. – Denn Oct 05 '20 at 06:00

0 Answers0