Search code examples
elasticsearchelasticsearch-php

Elasticsearch Completion Suggester ignores Index parameter and returns results for multiple indices


I'm using the PHP implementation of Elastic to use a Completion Suggester like this:

    $params_organisations = [
        'index' => $this->organisation_index,
        'body' => [
            "suggest" => [
                "suggestions" => [
                    'prefix' => $request->q,
                    "completion" => [
                        "field" => "suggest1",
                        "fuzzy" => ["fuzziness" => 0],
                        "skip_duplicates" => "false",
                        "size" => 7
                    ]
                ]
            ]
        ]
    ];

However, the response contains other indices as well:

suggest: {suggestions: Array(1)}
timed_out: false
took: 8
_shards:
failed: 3
failures: Array(3)
0:
index: ".kibana_1"
node: "xxxxxxxxx"
reason: {type: "illegal_argument_exception", reason: "no mapping found for field [suggest1]"}

I fear this might impact performance as some other indices do contain a suggest1, field as well and they are searched and returning results. I've not changed the names and sometimes I want to treat the suggest fields in a similar way, but is it problematic to have identical suggest-type field_names across indices?

Or is there a way to more explicitly define an index? I've also tried appending the index name to the endpoint, but same result. I've found an explicit suggest endpoint in the PHP implementation, but it seems to be deprecated? Any help is much appreciated!


Solution

  • Ok, so the problem was not with ElasticSearch, it turns out the index string coming from the configuration was not being processed correctly, yielding an empty string, causing Elastic to query all indices.