[英]Setting Elasticsearch analyzer for specific field using tire gem
我有一個Resource對象,該對象具有以下字段: title , description和body 。
使用輪胎寶石,我想使用標准分析儀來進行標題和描述 ,但是對於車身領域,我想使用雪球分析儀。
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.