Elasticsearch get a selection of predefined types as result in one query

I've got an ElasticSearch index with a large set of product properties.
They are all looking like that:

{'_id':1,'type':'manufacturer','name':'Toyota'},
{'_id':2,'type':'color','name':'Green'},
{'_id':3,'type':'category','name':'SUV Cars'},
{'_id':4,'type':'material','name':'Leather'},
{'_id':5,'type':'manufacturer','name':'BMW'},
{'_id':6,'type':'color','name':'Red'},
{'_id':7,'type':'category','name':'Cabrios'},
{'_id':8,'type':'material','name':'Steel'},
{'_id':9,'type':'category','name':'Cabrios Hardtop'},
{'_id':10,'type':'category','name':'Cabrios Softtop'},
... and 1 Mio. more ...

There are 4 different types of product properties existing: Categories,
Manufacturers, Colors and Materials.

The question: How can i query with only one query (it's a settled
performance requirement) the best matching result for each type?

So if i request a full text search query i.e. "Green Toyota Cabrios" i
should get the following results:

{'_id':2,'type':'color','name':'Green'},
{'_id':1,'type':'manufacturer','name':'Toyota'},
{'_id':7,'type':'category','name':'Cabrios'},
{one matching result of the 'material'-type if found by the query}

That would be the perfect result set, always at maximum 4 results (for
each 'type' one result)
. If there is no matching result for a specific
type available there should be just 3 result items returned
.

How is that possible with Elasticsearch? Thanks for your ideas!

More here:

--

I just answered on SOF:

I don't understand clearly your use case. What are you indexing in fact?
If you index cars, you should index it like:

{
  "color": "Green",
  "manufacturer": "Toyota",
  "category": "Cabrios"
}

That said, from the question you ask:

You can probably define your fields as not_indexed. That way, if you search for "Green Toyota Cabrios" if field "name" you won't get "Cabrios Hardtop".

Not sure I really answered but I don't see your use case…

Le 25 janv. 2013 à 15:05, dsteinmann david.steinmann@jiffuy.com a écrit :

I've got an ElasticSearch index with a large set of product properties. They are all looking like that:

{'_id':1,'type':'manufacturer','name':'Toyota'},
{'_id':2,'type':'color','name':'Green'},
{'_id':3,'type':'category','name':'SUV Cars'},
{'_id':4,'type':'material','name':'Leather'},
{'_id':5,'type':'manufacturer','name':'BMW'},
{'_id':6,'type':'color','name':'Red'},
{'_id':7,'type':'category','name':'Cabrios'},
{'_id':8,'type':'material','name':'Steel'},
{'_id':9,'type':'category','name':'Cabrios Hardtop'},
{'_id':10,'type':'category','name':'Cabrios Softtop'},
... and 1 Mio. more ...

There are 4 different types of product properties existing: Categories, Manufacturers, Colors and Materials.

The question: How can i query with only one query (it's a settled performance requirement) the best matching result for each type?

So if i request a full text search query i.e. "Green Toyota Cabrios" i should get the following results:

{'_id':2,'type':'color','name':'Green'},
{'_id':1,'type':'manufacturer','name':'Toyota'},
{'_id':7,'type':'category','name':'Cabrios'},
{one matching result of the 'material'-type if found by the query}

That would be the perfect result set, always at maximum 4 results (for each 'type' one result). If there is no matching result for a specific type available there should be just 3 result items returned.

How is that possible with Elasticsearch? Thanks for your ideas!

More here: http://stackoverflow.com/questions/14523222/elasticsearch-get-a-selection-of-predefined-types-as-result-in-one-query

--

--