我正在尝试从ElasticSearch查询中检索嵌套数据,基本上是试图从Movie模型中获取:
title
ratings
categories
现在,我尝试了2个轮胎设置,但两者都只回放电影标题,而不是评级或类别。例如。索引似乎只是:
curl -X POST "http://localhost:9200/movies/_search?pretty=true" -d ' { "query" : { "query_string" : {"query" : "t*"} }, "facets" : { "categories" : { "terms" : {"field" : "categories"} } } } ' { "took" : 16, "timed_out" : false, "_shards" : { "total" : 5, "successful" : 5, "failed" : 0 }, "hits" : { "total" : 3, "max_score" : 1.0, "hits" : [ { "_index" : "movies", "_type" : "movie", "_id" : "13", "_score" : 1.0, "_source" : {"description":null,"id":13,"title":"Tiny Plastic Men"} }, { "_index" : "movies", "_type" : "movie", "_id" : "32", "_score" : 1.0, "_source" : {"description":null,"id":32,"title":"The Extreme Truth"} }, { "_index" : "movies", "_type" : "movie", "_id" : "39", "_score" : 1.0, "_source" : {"description":null,"id":39,"title":"A Time of Day"} } ] }, "facets" : { "categories" : { "_type" : "terms", "missing" : 3, "total" : 0, "other" : 0, "terms" : [ ] } }
这是我的电影模型:
class Movie :categorizations belongs_to :user has_many :ratings mapping do indexes :id, type: 'integer' indexes :title, boost: 40 indexes :description, analyzer: 'snowball' indexes :categories do indexes :id, type: 'integer' indexes :name, type: 'string', index: 'not_analyzed' end indexes :ratings do indexes :id, type: 'integer' indexes :stars, type: 'integer' end end end
我的搜索实验的分支在这里:https://github.com/mulderp/moviedb/tree/categories
我如何为搜索工作制作方面,例如类型 - >的收视率。
答案 0 :(得分:2)
您实际上并未对类别或评级编制索引:它们位于映射中,但轮胎的默认实现to_indexed_json
只调用activerecord提供的to_json
方法。
您需要覆盖它以包含类别/评级信息,例如
def to_indexed_json
to_json(:include => [:categories, :ratings])
end