Ruby 按首字母列出的轮胎搜索返回术语
我正在使用Tire/ElasticSearch创建数据库中所有标签的字母浏览。但是,轮胎搜索会返回我想要的标签以及与同一项目关联的所有其他标签。因此,例如,如果我的信是“A”,并且一个项目有标签“土豚”和“饼干”,那么“土豚”和“饼干”都会显示为“A”查询的结果。我如何构造它,使我只得到“土豚”Ruby 按首字母列出的轮胎搜索返回术语,ruby,elasticsearch,tire,Ruby,elasticsearch,Tire,我正在使用Tire/ElasticSearch创建数据库中所有标签的字母浏览。但是,轮胎搜索会返回我想要的标签以及与同一项目关联的所有其他标签。因此,例如,如果我的信是“A”,并且一个项目有标签“土豚”和“饼干”,那么“土豚”和“饼干”都会显示为“A”查询的结果。我如何构造它,使我只得到“土豚” def explore #get alphabetical tire results with term and count only my_letter = "A" self.
def explore
#get alphabetical tire results with term and count only
my_letter = "A"
self.search_result = Tire.search index_name, 'tags' => 'count' do
query {string 'tags:' + my_letter + '*'}
facet 'tags' do
terms 'tags', :order => 'term'
end
end.results
end
映射:
{
items: {
item: {
properties: {
tags: {
type: "string",
index_name: "tag",
index: "not_analyzed",
omit_norms: true,
index_options: "docs"
},
}
}
}
}
以下是您需要更改的内容:
{
item: {
items: {
properties: {
tags: {
properties: {
type: "nested",
properties: {
value: {
type: "string",
analyzer: 'not_analyzed'
}
}
}
}
}
}
}
}
在计算Facet时应用Facet过滤器,因此您将只获得与您的条件匹配的Facet。由于性能问题,我更喜欢前缀查询而不是常规exp.查询。但我不确定前缀查询是否能解决您的问题。让我知道它不起作用。您能发布项目和标记的映射吗?另外,你能具体说明你想要什么吗?我的意思是,你想要这个项目和它的标签,还是你只需要标签?我只想要标签列表和计数。因此,如果单击A链接,将获得以A开头的所有标记以及每个标记在数据库中出现的次数。单击B标记,您将获得以B开头的所有标记,依此类推。我已经编辑了我的帖子,添加了一个映射。