繁体   English   中英

使用轮胎宝石为特定领域设置Elasticsearch分析仪

[英]Setting Elasticsearch analyzer for specific field using tire gem

我有一个Resource对象,该对象具有以下字段: titledescriptionbody

使用轮胎宝石,我想使用标准分析仪来进行标题描述 ,但是对于车身领域,我想使用雪球分析仪。

file I have the following code: 所以在我的文件中,我有以下代码:

mapping do
  indexes :title, type: 'string', :index => :not_analyzed, :store => true
  indexes :description, type: 'string'
  indexes :body, type: 'string', :analyzer => 'snowball'
end

def self.search(params)
  search_query = params[:query]

  tire.search(page: params[:page], per_page: 15) do |s|
    s.query { string params[:query], default_operator: "AND"} if params[:query].present?
    # do i need another line here specifically for description?
    #s.query { string "body:#{params[:query]}", analyzer: 'snowball'} if params[:query].present?
  end
end

我在映射中将分析器设置为雪球。 并且我验证了这是可行的,因为如果我运行以下命令:

curl -XGET localhost:9200/example/_search?q=body:cook

它将返回烹饪,煮熟等。

但是我希望能够通过以下查询

curl -XGET localhost:9200/example/_search?q=cooking

in the title and description fields and search for the word in the body . 我想elasticsearch搜索在标题描述字段字和搜索体内的词

这可能吗? 而且因为我不熟悉整个搜索游戏,所以这甚至是个好主意吗? 还是我只是在火坑里玩弄汽油罐的家伙?

在查询中未指定字段时,将搜索_all字段。 _all字段包含所有字段的副本,并且正在使用默认分析器。 可以将默认分析仪更改为滚雪球,如我如何为轮胎的弹性搜索如何设置默认分析仪中所述。 并且还可以控制_all字段中包含哪些字段。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM