我對 AWS ElastiSearch 完全陌生,并且正在嘗試在有關標記電影的資料集上做一些事情。資料集有五列:genres, movieId, tag, title, userId。每部電影的年份都包含在標題中Waterworld (1995)。我想看看 2002 年制作了多少帶有標簽true story的電影。因為我首先必須匹配日期,然后使用標簽過濾,最后計算我嘗試使用 bool 進行的電影,如下所示:
GET tagged_movies/_search
{
"query": {
"bool": {
"must": [
{
"regexp": {
"title": "(2002)"
}
}
],
"filter": [
{
"term": {
"tag": "true story"
}
}
],
"aggs": {
"by_numberofmovies": {
"terms": {
"field": "movieId"
}
}
}
}
}
}
但我收到以下錯誤:
{
"error" : {
"root_cause" : [
{
"type" : "x_content_parse_exception",
"reason" : "[18:7] [bool] unknown field [aggs]"
}
],
"type" : "x_content_parse_exception",
"reason" : "[18:7] [bool] unknown field [aggs]"
},
"status" : 400
}
我根本不明白,因為 bool 應該識別aggs。我試過查看檔案以及互聯網,但它說 bool 確實應該識別aggs. 有人可以指導問題可能出在哪里嗎?
這是此查詢應匹配的示例檔案的示例:
{
"_index" : "tagged_movies",
"_id" : "EgADsX8B2WnPqWZmot9b",
"_score" : 1.0,
"_source" : {
"@timestamp" : "2011-03-22T04:22:48.000 01:00",
"genres" : "Comedy",
"movieId" : 5283,
"tag" : "true story",
"title" : "National Lampoon's Van Wilder (2002)",
"userId" : 121,
"timestamp" : "2011-03-22 04:22:48"
}
uj5u.com熱心網友回復:
aggs不能在查詢塊內,aggs并且query是兄弟姐妹,您正確的查詢應該如下所示
{
"query": {
"bool": {
"must": [
{
"regexp": {
"title": "(2002)"
}
}
],
"filter": [
{
"match": {
"tag": "true story"
}
}
]
}
},
"aggs": {
"by_numberofmovies": {
"terms": {
"field": "movieId"
}
}
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/452255.html
