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?

4
  • Does this answer your question? Using multiple types or indexes in Elasticsearch php API Commented Oct 5, 2020 at 5:22
  • I referred to that link in my question saying I've tried it but it breaks my code. Commented Oct 5, 2020 at 5: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"? Commented Oct 5, 2020 at 5:30
  • 1
    @Jeto Thank you. You made me review that question and saw that comment. Now it works perfectly. Commented Oct 5, 2020 at 6:00

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.