# Instrument names autocomplete (return unique matching values)

**URL:** <https://discuss.elastic.co/t/instrument-names-autocomplete-return-unique-matching-values/65551>\
**Category:** Elasticsearch\
**Created:** [November 9, 2016, 7:43pm UTC](https://discuss.elastic.co/t/instrument-names-autocomplete-return-unique-matching-values/65551 "2016-11-09T19:43:09Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![artexanis](https://avatars.discourse-cdn.com/v4/letter/a/3be4f8/32.png) [@artexanis](https://discuss.elastic.co/u/artexanis)\
**Post date:** [November 9, 2016, 7:43pm UTC](https://discuss.elastic.co/t/instrument-names-autocomplete-return-unique-matching-values/65551/1 "2016-11-09T19:43:09Z")

</div>

I recently started looking at elasticsearch, I'm in the process of learning what it can do and decide how I can use it in my projects.

For one project I used a couchdb (noSQL) database. The client can search it using couchdb views. Easy, but limited in functionality.  
I'd like to have elasticsearch to open up the data in a far more rich way.

Searching for composers and titles of musical pieces is now handled by elasticsearch with amazingly fast 'query\_string's. And it's fuzzy!

There is one thing however I did not manage to accomplish with elasticsearch, but I'm pretty sure it's possible, I'm just missing it.

It's about the autocomplete functionality when entering instrument names.  
For example:  
I have 2 documents (musical pieces) with different instruments needed to play them:

> `{ title: 'Awesome Piece', authors: [{ name: 'John Doe', role: 'composer' }, { name: 'Shakespeare', role: 'lyricist' }], instruments: ['soprano', 'alto', 'tenor', 'bass', 'trompet', 'trompet', 'piano'] }`

* * *

> `{ title: 'Not so Awesome Piece', authors: [{ name: 'Another J. Doe', role: 'composer' }, { name: 'Little John', role: 'arranger' }], instruments: ['trombone', 'organ'] }`

To enter a new musical piece there is a field to insert instrument names. I'd like the offer an autocomplete.  
So if the user types 't', I want a list of all instruments maching 't\*': ['tenor', 'trompet', 'trombone'], if he types 'tr', I need: ['trompet', 'trombone']

The best I coold find was a query with an aggregation, but it searches for documents and aggregates them as a whole, returning all instruments of the document(s) found with the query.

And off course, I want the autocomplete to be fuzzy in the end.

Can anybody point me in a direction?  
Thanks in advance!

---

<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:** [December 7, 2016, 7:43pm UTC](https://discuss.elastic.co/t/instrument-names-autocomplete-return-unique-matching-values/65551/2 "2016-12-07T19:43:25Z")

</div>

Closed on December 7, 2016, 7:43pm UTC

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