Elasticsearch : bool with regex, filter and aggs
Elastisearch : bool with regexp, filter and aggs
我是 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"
}
aggs
不能在查询块内,aggs
和 query
是兄弟,你正确的查询应该像下面这样
{
"query": {
"bool": {
"must": [
{
"regexp": {
"title": "(2002)"
}
}
],
"filter": [
{
"match": {
"tag": "true story"
}
}
]
}
},
"aggs": {
"by_numberofmovies": {
"terms": {
"field": "movieId"
}
}
}
}
我是 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"
}
aggs
不能在查询块内,aggs
和 query
是兄弟,你正确的查询应该像下面这样
{
"query": {
"bool": {
"must": [
{
"regexp": {
"title": "(2002)"
}
}
],
"filter": [
{
"match": {
"tag": "true story"
}
}
]
}
},
"aggs": {
"by_numberofmovies": {
"terms": {
"field": "movieId"
}
}
}
}