1

我的电影属于一种类型并且有多个评级。使用 ElasticSearch,我想先对 Genres 进行分面搜索,然后是 Ratings。

我在这里阅读了这个想法:http ://www.elasticsearch.org/guide/reference/api/search/facets/

但我很困惑如何理解这个 Curl 查询的输出:

curl -X POST "http://localhost:9200/movies/_search?pretty=true" -d '
 {
    “查询”:{“查询字符串”:{“查询”:“T*”}},
    “方面”:{
      “类别”:{“条款”:{“字段”:“类别”}}
    }
  }
'
{
  “接受”:35,
  “超时”:假,
  “_shards”:{
    “总数”:5,
    “成功”:5,
    “失败”:0
  },
  “命中”:{
    “总数”:3,
    “最大分数”:1.0,
    “命中”:[{
      "_index" : "电影",
      "_type" : "电影",
      “_id”:“13”,
      "_score" : 1.0, "_source" : {"category_id":2,"created_at":"2013-05-03T16:40:21Z","description":null,"title":"小塑料人"," updated_at":"2013-05-03T16:40:21Z","user_id":null}
    }, {
      "_index" : "电影",
      "_type" : "电影",
      “_id”:“32”,
      "_score" : 1.0, "_source" : {"category_id":14,"created_at":"2013-05-03T16:55:02Z","description":null,"title":"The Extreme Truth"," updated_at":"2013-05-03T16:55:02Z","user_id":null}
    }, {
      "_index" : "电影",
      "_type" : "电影",
      “_id”:“39”,
      "_score" : 1.0, "_source" : {"category_id":7,"created_at":"2013-05-03T16:55:02Z","description":null,"title":"一天中的某个时间", "updated_at":"2013-05-03T16:55:02Z","user_id":null}
    }]
  },
  “方面”:{
    “类别”:{
      “_type”:“条款”,
      “失踪”:3,
      “总计”:0,
      “其他”:0,
      “条款”:[]
    }
  }

我有一些以“T”开头的电影,但另外我会期待类型/类别“惊悚片”的电影。

因此,我可以从上面的 JSON 中读取什么?

4

2 回答 2

3

您的方面似乎与您可能应该使用的文档中的任何字段都不匹配:

curl -X POST "http://localhost:9200/movies/_search?pretty=true" -d '
 {
    "query" : { "query_string" : {"query" : "T*"} },
    "facets" : {
      "categories" : { "terms" : {"field" : "category_id"} }
    }
  }
'

然后你会得到一个 category_id 列表和每个 category_id 中的文档数

于 2013-05-04T21:51:47.487 回答
2

刻面已弃用。请参阅https://www.elastic.co/guide/en/elasticsearch/reference/1.6/search-facets.html

更好的选择是使用聚合:https ://www.elastic.co/guide/en/elasticsearch/reference/1.6/search-aggregations.html

于 2015-07-16T19:15:13.663 回答