[英]Elasticsearch-rails, highlights query
我正在尝试从Elasticsearch-rails gem中获得亮点,但是我无法使其正常工作。
我的搜索方法:
query = {
query: {
filtered: {
query: {
match: {
_all: params[:q]
}
},
filter: {
term: {
active: true
}
}
},
},
highlight: {
fields: {
_all: {fragment_size: 150, number_of_fragments: 3}
}
}
}
@results = Elasticsearch::Model.search(query, [Market, Component]).results
当我在视图中映射结果以检查是否有突出显示时,我得到了false
数组:
= @results.map(&:highlight?)
我在这里阅读了Elasticsearch文档: https : //www.elastic.co/guide/en/elasticsearch/reference/current/search-request-highlighting.html和gem的文档在这里: https : //github.com/elastic / elasticsearch-rails / tree / master / elasticsearch-model ,我的查询似乎是正确的。 不知道如何进行。
显然,解决方案是使用"*"
而不是"_all"
:
query = {
query: {
filtered: {
query: {
match: {
_all: params[:q]
}
},
filter: {
term: {
active: true
}
}
},
},
highlight: {
tags_schema: "styled",
fields: {
:"*" => {}
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.