Instrument names autocomplete (return unique matching values)


(Hans Vereyken) #1

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!


(system) #2

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