Ruby on rails Elasticsearch、multi_匹配、ruby on rails
我想使用ElasticSearch搜索我的产品集合 如果我有这样一个对象:Ruby on rails Elasticsearch、multi_匹配、ruby on rails,ruby-on-rails,
elasticsearch,Ruby On Rails,
elasticsearch,我想使用ElasticSearch搜索我的产品集合 如果我有这样一个对象: { name: "Product Name", producer: "Best Producer"} mapping do indexes :name, type: :string, search_analyzer: :str_search_analyzer, index_analyzer: :str_index_analyzer indexes :producer, type: :string, search
{ name: "Product Name", producer: "Best Producer"}
mapping do
indexes :name, type: :string, search_analyzer: :str_search_analyzer, index_analyzer: :str_index_analyzer
indexes :producer, type: :string, search_analyzer: :str_search_analyzer, index_analyzer: :str_index_analyzer
end
我想通过搜索以下内容来查找此对象:
Product.search(
{
multi_match: {
query: params[:search_input],
type: "phrase_prefix",
fields: ["name", "producer"],
operator: "and"
}
})
如何改进它?您可以使用bool、should和term来表示多重匹配参数
Product.search(:query => @query)
@query = {
:bool => {
:must => @must_queries
}
}
:bool => {
:should => [
{
:terms => {
:your_mathcing_field_name => value
}
}
]
}
您可以为每个字段输入多个术语。谢谢您的回答 我设法解决了这个问题。 这是我的解决方案:
Product.search(
{
multi_match: {
query: params[:search_input],
type: "best_fields",
fields: ["name", "producer"],
operator: "and"
}
}
)
我的映射如下所示:
{ name: "Product Name", producer: "Best Producer"}
mapping do
indexes :name, type: :string, search_analyzer: :str_search_analyzer, index_analyzer: :str_index_analyzer
indexes :producer, type: :string, search_analyzer: :str_search_analyzer, index_analyzer: :str_index_analyzer
end
你能展示你的地图吗?用这样的方法得到它: