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

**URL:** <https://discuss.elastic.co/t/search-without-duplicates-sort-by-score-highlighting-and-with-fuzzy-search/144830>\
**Category:** Elasticsearch\
**Created:** [August 17, 2018, 6:59am UTC](https://discuss.elastic.co/t/search-without-duplicates-sort-by-score-highlighting-and-with-fuzzy-search/144830 "2018-08-17T06:59:58Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![hestus](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/hestus/32/34577_2.png) [@hestus](https://discuss.elastic.co/u/hestus)\
**Post date:** [August 17, 2018, 6:59am UTC](https://discuss.elastic.co/t/search-without-duplicates-sort-by-score-highlighting-and-with-fuzzy-search/144830/1 "2018-08-17T06:59:58Z")

</div>

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

```auto
          $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](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-suggesters.html) 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.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [September 14, 2018, 7:05am UTC](https://discuss.elastic.co/t/search-without-duplicates-sort-by-score-highlighting-and-with-fuzzy-search/144830/2 "2018-09-14T07:05:27Z")

</div>

Closed on September 14, 2018, 7:05am UTC

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