Elasticsearch可以在一个查询中获得预定义类型的选择 [英] Elasticsearch get a selection of predefined types as result in one query
问题描述
{'_ id':1,'type':'manufacturer','name' 丰田,
{'_id':2,'type':'color','name':'Green'},
{'_id':3,'type' ','name':'SUV Cars'},
{'_id':4,'type':'material','name':'Leather'},
{'_id' ,'''''''''''''''''''''','''''''''''' {'_id':7,'type':'category','name':'Cabrios'},
{'_id':8,'type':'material','name' },
{'_id':9,'type':'category','name':'Cabrios Hardtop'},
{'_id':10,'type' 'name':'Cabrios Softtop'},
...和1 Mio.更多...
现有4种不同类型的产品属性:类别,制造商,颜色和材料
问题:如何查询只有一个查询(这是一个稳定的性能要求)每个最佳匹配结果类型?
所以如果我要求一个全文搜索查询,即绿色丰田Cabrios,我应该得到以下结果:
{'_ id':2,'type':'color','name':'Green'},
{'_id' 1,'type':'manufacturer','name':'Toyota'},
{'_id':7,'type':'category','name':'Cabrios'},
{由查询找到的'material'类型的一个匹配结果}
那将是完美结果集,总是最多4个结果(每个类型一个结果)。如果没有可用的特定类型的匹配结果,则应该只返回3个结果项。
如何使用Elasticsearch?感谢您的想法!
我不明白你的用例。你实际上是什么索引?
如果你索引汽车,你应该索引:
{
color:绿色,
制造商:丰田,
category:Cabrios
}
从您提出的问题中可以看出:
您可以将字段定义为not_indexed。这样,如果您搜索绿色丰田Cabrios如果字段名称,您将不会得到Cabrios Hardtop。
不知道我真的回答了,但我看不到你的用例...
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!
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...
这篇关于Elasticsearch可以在一个查询中获得预定义类型的选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!