[英]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. 我有一个带有大量产品属性的ElasticSearch索引。 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. 现有4种不同类型的产品属性:类别,制造商,颜色和材料。
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 ie "Green Toyota Cabrios" i should get the following results: 因此,如果我请求全文搜索查询,即“ Green Toyota Cabrios”,我应该得到以下结果:
{'_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) . 那将是一个完美的结果集, 始终最多有4个结果(对于每个“类型”一个结果) 。 If there is no matching result for a specific type available there should be just 3 result items returned .
如果没有可用的特定类型的匹配结果,则应仅返回3个结果项 。
How is that possible with Elasticsearch? Elasticsearch怎么可能? Thanks for your ideas!
感谢您的想法!
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. 您可能可以将字段定义为not_indexed。 That way, if you search for "Green Toyota Cabrios" if field "name" you won't get "Cabrios Hardtop".
这样,如果在“名称”字段中搜索“ Green Toyota Cabrios”,则不会获得“ Cabrios Hardtop”。
Not sure I really answered but I don't see your use case... 不确定我是否真的回答过,但看不到您的用例...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.