Elasticsearch Completion

121 views Asked by At

I have a elasticsearch index which i update every 10 minutes via cronjob. In this index i have a completion field which works as expected. But i have one little problem. Lets say i have a "article" field where i change a value from "a" to "b". After 10 minutes the index is been updated and the document which holds article "a" is been updated to article "b". Everything as expected. But my completion field now holds both values. "a" and "b" both with the same id.

How can this happen?

2

There are 2 answers

0
Stillmatic1985 On

Found the answer in the docs.

The suggest data structure might not reflect deletes on documents immediately. You may need to do an Optimize for that. You can call optimize with the only_expunge_deletes=true to only cater for deletes or alternatively call a Merge operation.

0
Stillmatic1985 On

Mapping:

'suggest'   => array(
    'type'                => 'completion',
    'payloads'            => true,
    'preserve_separators' => false,
    'search_analyzer'     => 'standard',
    'index_analyzer'      => 'standard'
),

How i set the field:

'suggest'  => array(
    'input'   => array(
        $result["Name"],
        $result["Name"],
        $result["Name2"],
        $result["Name3"],
        $result["Name4"],
        $result["Name5"]
    ),
    'output'  => $result["Name"].' (' . $result["Name1"].', '.$result["Name2"].')',
    'payload' => array(
        'id' => $result["ID"]
     )
 )