Search without duplicates, sort by score, highlighting and with fuzzy search

For my use case I need as the title states. Currently I have it working but it is rather slow. This is my implementation:

          $query['body']['aggs'] = [
                'title' => [
                    'terms' => [
                        'size' => 10,
                        'field' => 'title',
                        'order' => ['max_score' => 'desc']
                    ],
                    'aggs' => [
                        'max_score' => [
                            'max' => [
                                'script' => '_score'
                            ]
                        ],
                        'highlight' => [
                            'top_hits' => [
                                '_source' => [
                                    'includes' => 'title'
                                ],
                                'size' => 1,
                                'highlight' => [
                                    'fields' => [
                                        'title' => [
                                            'pre_tags' => '<em class="highlight">',
                                            'post_tags' => '</em>'
                                        ]
                                    ]
                                ]
                            ]
                        ]
                    ]
                ]
            ];
        }

Elastic suggesters are almost perfect for my use case but I want to be able to start searching in the middle of a string instead of only prefixing it.

Since the implementation from above is rather slow and suggesters don't fit my exact use case I now have a duplicate bucket where I only store unique values. This isn't ideal since I could get vast amount of buckets in the future.

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