ElasticSearch-格式错误的查询(RoR) [英] ElasticSearch - Malformed Query (RoR)
问题描述
我正在尝试使用elasticsearch和ruby-on-rails建立一个现有项目。我可以启动并运行该项目,但是elasticsearch查询对我和我的同事都不会返回各种错误消息:
[400] { error:{ root_cause:[{ type: parsing_exception, reason: [and]查询格式错误,查询名称后没有start_object, line:1, col:896} ], type: parsing_exception, reason: [和]查询格式错误,查询名称后没有start_object, line:1, col:896}, status:400}
显然,这使我相信这与我的设置有关。我已经安装了相同版本的(2.4),但是即使项目随附了安装命令,也是如此:
rake环境elasticsearch:import:all DIR = app / models FORCE = y
给我一个超时错误。我已经检查过,该服务正在运行。由于我在这个问题上呆了两天,对此设置的任何帮助将不胜感激。
在此先感谢。 / p>
编辑:我认为问题不在于查询本身,因为这对我的同事有效,但是它如下:
{:date_range => {:来自=>星期一,
2016年8月1日00:00:00 UTC + 00:00,
:至=>星期一,
2017年7月31日00:00:00 UTC + 00:00
} ,: activity_only => nil
},@ pupils = [#<学生ID:1042,名字: Mark,姓氏: Mekhaiel,生日: 2017-03-19,等级:0,组ID:95,created_at: 2017-07-31 08:59:59, Updated_at: 2017-07-31 09:48:27,用户名: m.mekhaiel1,图片:0,颜色:0,存档:false,sub_group_id:nil,得分:20,Deleted_at:nil> ],@search =#< PupilCreditSearch:0x007fc961801308 @interval =:月,@ page = 1,@ per = 25,@ pupil_id = [1042],@ date_range = {:from =>星期一,
2016年8月1日00:00:00 UTC + 00:00,
:至=>星期一,
2017年7月31日00:00:00 UTC + 00:00
},@ queries = [#<搜索::查询:0x007fc964791bb8 @query = nil,@ fields = [],@ type =:multi_match,@ options = {:fields => [],
:类型=> :cross_fields
}> ],@ filters = [#<搜索::过滤器:0x007fc964756db0 @name =:瞳孔ID,@ value = [1042],@ type =:条件,@ options = {}> ],@aggregations = {:years_created => #<搜索::聚合:0x007fc9647a32f0 @type =:date_histogram,
@field =:created_at,
@options = {:field => :created_at,
:type => :date_histogram,
:params => {:间隔=> :年
}
}> ,
:months_created => #<搜索::聚合:0x007fc9647a30c0 @type =:date_histogram,
@field =:created_at,
@options = {:field => :created_at,
:type => :date_histogram,
:params => {:间隔=> :月
}
}> ,
:date_ranges => #<搜索::聚合:0x007fc9647a2800 @type =:date_range,
@field =:created_at,
@options = {:字段=> :created_at,
:type => :date_range,
:params => {:keyed => true,
:范围=> [{:from => now / w,
:==> now + 1w / w,
:键=> :this_week
},{:from => now / M,
:= => 现在+ 1M / M,
:键=> :this_month
},{:from => now-1w / w,
:= => now-2w / w,
:键=> :last_week
},{:from => now-1M / M,
:至=> now-2M / M,
:键=> :last_month
},{:from => 2016-09-01,
:= => 2017-08-31,
:键=> :Academic_year
}]
}
}> ,
:组=> #<搜索::聚合:0x007fc9647a2260 @type =:项,
@field =:瞳孔ID,
@options = {:aggs => {:all_dates => #<搜索::聚合:0x007fc9647a22d8 @type =:date_histogram,
@field =:created_at,
@options = {:params => {:间隔=> :month
},
:aggs => {:total_points => #< Search :: Aggregation:0x007fc9647a2440 @type =:sum,
@field =:点,
@options = {}> ,
:running_total => #<搜索::聚合:0x007fc9647a2350 @type =:累积和,
@ field = nil,
@options = {:参数=> {:buckets_path => total_points
}
}>
}
}>
}
}> ,
:options => #<搜索::聚合:0x007fc9647a1518 @type =:全局,
@ field = nil,
@options = {:aggs => {:已过滤=> #<搜索::聚合:0x007fc9647a1590 @type =:过滤器,
@ field = nil,
@options = {:参数=> {:和=> [{:range => {:created_at => {:gte =>星期一,
2016年8月1日00:00:00 UTC + 00:00,
:lt =>星期一,
2017年7月31日00:00:00 UTC + 00:00
}
}
},{:条件=> {:瞳孔ID => [1042]
}
}]
},
:aggs => {:类别=> #<搜索::聚合:0x007fc9647a1b80 @type =:条款,
@field = category,
@options = {:忽略=>真
}> ,
:topic_ids => #<搜索::聚合:0x007fc9647a19a0 @type =:条款,
@field = topic_id,
@options = {:忽略=>真
}> ,
:learning_objective_ids => #<搜索::聚合:0x007fc9647a17c0 @type =:条款,
@field = learning_objective_id,
@options = {:忽略=>真
}> ,
:completed_activities => #<搜索::聚合:0x007fc9647a1608 @type =:项,
@field =:瞳孔ID,
@options = {:aggs => {:活动=> #<搜索::聚合:0x007fc9647a1680 @type =:过滤器,
@ field = nil,
@options = {:参数=> {:和=> [{:条款=> {:category => [0,1,2,3]
}
}]
}
}>
}
}>
}
}>
}
}>
},@ request =#<搜索::请求:0x007fc964753548 @params = {:查询=> {:bool => {:必须=> [{:match_all => {}
}],
:filter => [{:条款=> {:瞳孔ID => [1042]
}
}]
}
},
:aggs => {:years_created => {:date_histogram => {:字段=> :created_at,
:interval => :年
}
},
:months_created => {:date_histogram => {:字段=> :created_at,
:interval => :month
}
},
:date_ranges => {:date_range => {:字段=> :created_at,
:keyed => true,
:范围=> [{:from => now / w,
:==> now + 1w / w,
:键=> :this_week
},{:from => now / M,
:= => 现在+ 1M / M,
:键=> :this_month
},{:from => now-1w / w,
:= => now-2w / w,
:键=> :last_week
},{:from => now-1M / M,
:至=> now-2M / M,
:键=> :last_month
},{:from => 2016-09-01,
:= => 2017-08-31,
:键=> :Academic_year
}]
}
},
:分组=> {:条款=> {:字段=> :student_id
},
:aggs => {:all_dates => {:date_histogram => {:字段=> :created_at,
:interval => :month
},
:aggs => {:total_points => {:sum => {:字段=> :点
}
},
:running_total => {:累积总和=> {:buckets_path => total_points
}
}
}
}
}
},
:options => {:全局=> {},
:aggs => {:已过滤=> {:filter => {:和=> [{:范围=> {:created_at => {:gte =>星期一,
2016年8月1日00:00:00 UTC + 00:00,
:lt =>星期一,
2017年7月31日00:00:00 UTC + 00:00
}
}
},{:条件=> {:瞳孔ID => [1042]
}
}]
},
:aggs => {:类别=> {:条款=> {:字段=> 类别
}
},
:topic_ids => {:条款=> {:字段=> topic_id
}
},
:learning_objective_ids => {:条款=> {:字段=> learning_objective_id
}
},
:completed_activities => {:条款=> {:字段=> :student_id
},
:aggs => {:活动=> {:filter => {:和=> [{:条款=> {:category => [0,1,2,3]
}
}]
}
}
}
}
}
}
}
}
}
}>> ,@options =#< ReportOptions:0x007fc96b663258 @search =#< PupilCreditSearch:0x007fc961801308 @interval =:月,@ page = 1,@ per = 25,@ pupil_id = [1042],@ date_range = {:from =>星期一,
2016年8月1日00:00:00 UTC + 00:00,
:至=>星期一,
2017年7月31日00:00:00 UTC + 00:00
},@ queries = [#<搜索::查询:0x007fc964791bb8 @query = nil,@ fields = [],@ type =:multi_match,@ options = {:fields => [],
:类型=> :cross_fields
}> ],@ filters = [#<搜索::过滤器:0x007fc964756db0 @name =:瞳孔ID,@ value = [1042],@ type =:条件,@ options = {}> ],@aggregations = {:years_created => #<搜索::聚合:0x007fc9647a32f0 @type =:date_histogram,
@field =:created_at,
@options = {:field => :created_at,
:type => :date_histogram,
:params => {:间隔=> :年
}
}> ,
:months_created => #<搜索::聚合:0x007fc9647a30c0 @type =:date_histogram,
@field =:created_at,
@options = {:field => :created_at,
:type => :date_histogram,
:params => {:间隔=> :月
}
}> ,
:date_ranges => #<搜索::聚合:0x007fc9647a2800 @type =:date_range,
@field =:created_at,
@options = {:字段=> :created_at,
:type => :date_range,
:params => {:键控=> true,
:范围=> [{:from => now / w,
:==> now + 1w / w,
:键=> :this_week
},{:from => now / M,
:= => 现在+ 1M / M,
:键=> :this_month
},{:from => now-1w / w,
:= => now-2w / w,
:键=> :last_week
},{:from => now-1M / M,
:至=> now-2M / M,
:键=> :last_month
},{:from => 2016-09-01,
:= => 2017-08-31,
:键=> :Academic_year
}]
}
}> ,
:组=> #<搜索::聚合:0x007fc9647a2260 @type =:项,
@field =:瞳孔ID,
@options = {:aggs => {:all_dates => #<搜索::聚合:0x007fc9647a22d8 @type =:date_histogram,
@field =:created_at,
@options = {:params => {:间隔=> :month
},
:aggs => {:total_points => #< Search :: Aggregation:0x007fc9647a2440 @type =:sum,
@field =:点,
@options = {}> ,
:running_total => #<搜索::聚合:0x007fc9647a2350 @type =:累积和,
@ field = nil,
@options = {:参数=> {:buckets_path => total_points
}
}>
}
}>
}
}> ,
:options => #<搜索::聚合:0x007fc9647a1518 @type =:全局,
@ field = nil,
@options = {:aggs => {:已过滤=> #<搜索::聚合:0x007fc9647a1590 @type =:过滤器,
@ field = nil,
@options = {:参数=> {:和=> [{:范围=> {:created_at => {:gte =>星期一,
2016年8月1日00:00:00 UTC + 00:00,
:lt =>星期一,
2017年7月31日00:00:00 UTC + 00:00
}
}
},{:条件=> {:瞳孔ID => [1042]
}
}]
},
:aggs => {:类别=> #<搜索::聚合:0x007fc9647a1b80 @type =:条款,
@field = category,
@options = {:忽略=>真
}> ,
:topic_ids => #<搜索::聚合:0x007fc9647a19a0 @type =:条款,
@field = topic_id,
@options = {:忽略=>真
}> ,
:learning_objective_ids => #<搜索::聚合:0x007fc9647a17c0 @type =:条款,
@field = learning_objective_id,
@options = {:忽略=>真
}> ,
:completed_activities => #<搜索::聚合:0x007fc9647a1608 @type =:项,
@field =:瞳孔ID,
@options = {:aggs => {:活动=> #<搜索::聚合:0x007fc9647a1680 @type =:过滤器,
@ field = nil,
@options = {:参数=> {:和=> [{:条款=> {:category => [0,1,2,3]
}
}]
}
}>
}
}>
}
}>
}
}>
},@ request =#<搜索::请求:0x007fc964753548 @params = {:查询=> {:bool => {:必须=> [{:match_all => {}
}],
:过滤器=> [{:条款=> {:瞳孔ID => [1042]
}
}]
}
},
:aggs => {:years_created => {:date_histogram => {:字段=> :created_at,
:interval => :年
}
},
:months_created => {:date_histogram => {:字段=> :created_at,
:interval => :month
}
},
:date_ranges => {:date_range => {:字段=> :created_at,
:keyed => true,
:范围=> [{:from => now / w,
:==> now + 1w / w,
:键=> :this_week
},{:from => now / M,
:= => 现在+ 1M / M,
:键=> :this_month
},{:from => now-1w / w,
:= => now-2w / w,
:键=> :last_week
},{:from => now-1M / M,
:至=> now-2M / M,
:键=> :last_month
},{:from => 2016-09-01,
:= => 2017-08-31,
:键=> :Academic_year
}]
}
},
:分组=> {:条款=> {:字段=> :student_id
},
:aggs => {:all_dates => {:date_histogram => {:字段=> :created_at,
:interval => :month
},
:aggs => {:total_points => {:sum => {:字段=> :点
}
},
:running_total => {:累积总和=> {:buckets_path => total_points
}
}
}
}
}
},
:options => {:全局=> {},
:aggs => {:已过滤=> {:filter => {:和=> [{:range => {:created_at => {:gte =>星期一,
2016年8月1日00:00:00 UTC + 00:00,
:lt =>星期一,
2017年7月31日00:00:00 UTC + 00:00
}
}
},{:条件=> {:瞳孔ID => [1042]
}
}]
},
:aggs => {:类别=> {:条款=> {:字段=> 类别
}
},
:topic_ids => {:条款=> {:字段=> topic_id
}
},
:learning_objective_ids => {:条款=> {:字段=> learning_objective_id
}
},
:completed_activities => {:条款=> {:字段=> :student_id
},
:aggs => {:活动=> {:filter => {:和=> [{:条款=> {:category => [0,1,2,3]
}
}]
}
}
}
}
}
}
}
}
}
}
问题在于聚合之一,即:
:filter => {:and => [...]}
...这使我得出结论,实际上您可能正在运行Elasticsearch 5而不是2.4机器,因为此语法已在版本5中删除,而支持:
:filter => {:bool => {:必须:[...]}}
使用 curl localhost:9200验证elasticsearch版本
(或您的应用连接到的实际主机/端口)。
I'm trying to set up an existing project using elasticsearch and ruby-on-rails. I can get the project up and running however elasticsearch queries return various error message for me and none of my colleagues:
[400] {"error":{"root_cause":[{"type":"parsing_exception","reason":"[and] query malformed, no start_object after query name","line":1,"col":896}],"type":"parsing_exception","reason":"[and] query malformed, no start_object after query name","line":1,"col":896},"status":400}
This obviously leads me to believe it's something to do with my setup. I've installed the same version of them (2.4), however even the setup command that was supplied with the project:
rake environment elasticsearch:import:all DIR=app/models FORCE=y
gives me a timeout error. I've checked and the service is running. Any help as to what could be wrong with my set up would be greatly appreciated as I'm at a dead end for 2 days on this.
Thanks in advance.
EDIT: I don't think the issue is with the query itself as this works for my colleagues however it is as follows:
{: date_range => {: from => Mon,
01 Aug 2016 00: 00: 00 UTC + 00: 00,
: to => Mon,
31 Jul 2017 00: 00: 00 UTC + 00: 00
}, : activities_only => nil
}, @pupils = [# < Pupil id: 1042, first_name: "Mark", last_name: "Mekhaiel", date_of_birth: "2017-03-19", level: 0, group_id: 95, created_at: "2017-07-31 08:59:59", updated_at: "2017-07-31 09:48:27", username: "m.mekhaiel1", picture: 0, color: 0, archived: false, sub_group_id: nil, score: 20, deleted_at: nil > ], @search = # < PupilCreditSearch: 0x007fc961801308 @interval = : month, @page = 1, @per = 25, @pupil_id = [1042], @date_range = {: from => Mon,
01 Aug 2016 00: 00: 00 UTC + 00: 00,
: to => Mon,
31 Jul 2017 00: 00: 00 UTC + 00: 00
}, @queries = [# < Search::Query: 0x007fc964791bb8 @query = nil, @fields = [], @type = : multi_match, @options = {: fields => [],
: type => : cross_fields
} > ], @filters = [# < Search::Filter: 0x007fc964756db0 @name = : pupil_id, @value = [1042], @type = : terms, @options = {} > ], @aggregations = {: years_created => # < Search::Aggregation: 0x007fc9647a32f0 @type = : date_histogram,
@field = : created_at,
@options = {: field => : created_at,
: type => : date_histogram,
: params => {: interval => : year
}
} > ,
: months_created => # < Search::Aggregation: 0x007fc9647a30c0 @type = : date_histogram,
@field = : created_at,
@options = {: field => : created_at,
: type => : date_histogram,
: params => {: interval => : month
}
} > ,
: date_ranges => # < Search::Aggregation: 0x007fc9647a2800 @type = : date_range,
@field = : created_at,
@options = {: field => : created_at,
: type => : date_range,
: params => {: keyed => true,
: ranges => [{: from => "now/w",
: to => "now+1w/w",
: key => : this_week
}, {: from => "now/M",
: to => "now+1M/M",
: key => : this_month
}, {: from => "now-1w/w",
: to => "now-2w/w",
: key => : last_week
}, {: from => "now-1M/M",
: to => "now-2M/M",
: key => : last_month
}, {: from => "2016-09-01",
: to => "2017-08-31",
: key => : academic_year
}]
}
} > ,
: groups => # < Search::Aggregation: 0x007fc9647a2260 @type = : terms,
@field = : pupil_id,
@options = {: aggs => {: all_dates => # < Search::Aggregation: 0x007fc9647a22d8 @type = : date_histogram,
@field = : created_at,
@options = {: params => {: interval => : month
},
: aggs => {: total_points => # < Search::Aggregation: 0x007fc9647a2440 @type = : sum,
@field = : points,
@options = {} > ,
: running_total => # < Search::Aggregation: 0x007fc9647a2350 @type = : cumulative_sum,
@field = nil,
@options = {: params => {: buckets_path => "total_points"
}
} >
}
} >
}
} > ,
: options => # < Search::Aggregation: 0x007fc9647a1518 @type = : global,
@field = nil,
@options = {: aggs => {: filtered => # < Search::Aggregation: 0x007fc9647a1590 @type = : filter,
@field = nil,
@options = {: params => {: and => [{: range => {: created_at => {: gte => Mon,
01 Aug 2016 00: 00: 00 UTC + 00: 00,
: lt => Mon,
31 Jul 2017 00: 00: 00 UTC + 00: 00
}
}
}, {: terms => {: pupil_id => [1042]
}
}]
},
: aggs => {: categories => # < Search::Aggregation: 0x007fc9647a1b80 @type = : terms,
@field = "category",
@options = {: ignore => true
} > ,
: topic_ids => # < Search::Aggregation: 0x007fc9647a19a0 @type = : terms,
@field = "topic_id",
@options = {: ignore => true
} > ,
: learning_objective_ids => # < Search::Aggregation: 0x007fc9647a17c0 @type = : terms,
@field = "learning_objective_id",
@options = {: ignore => true
} > ,
: completed_activities => # < Search::Aggregation: 0x007fc9647a1608 @type = : terms,
@field = : pupil_id,
@options = {: aggs => {: activities => # < Search::Aggregation: 0x007fc9647a1680 @type = : filter,
@field = nil,
@options = {: params => {: and => [{: terms => {: category => [0, 1, 2, 3]
}
}]
}
} >
}
} >
}
} >
}
} >
}, @request = # < Search::Request: 0x007fc964753548 @params = {: query => {: bool => {: must => [{: match_all => {}
}],
: filter => [{: terms => {: pupil_id => [1042]
}
}]
}
},
: aggs => {: years_created => {: date_histogram => {: field => : created_at,
: interval => : year
}
},
: months_created => {: date_histogram => {: field => : created_at,
: interval => : month
}
},
: date_ranges => {: date_range => {: field => : created_at,
: keyed => true,
: ranges => [{: from => "now/w",
: to => "now+1w/w",
: key => : this_week
}, {: from => "now/M",
: to => "now+1M/M",
: key => : this_month
}, {: from => "now-1w/w",
: to => "now-2w/w",
: key => : last_week
}, {: from => "now-1M/M",
: to => "now-2M/M",
: key => : last_month
}, {: from => "2016-09-01",
: to => "2017-08-31",
: key => : academic_year
}]
}
},
: groups => {: terms => {: field => : pupil_id
},
: aggs => {: all_dates => {: date_histogram => {: field => : created_at,
: interval => : month
},
: aggs => {: total_points => {: sum => {: field => : points
}
},
: running_total => {: cumulative_sum => {: buckets_path => "total_points"
}
}
}
}
}
},
: options => {: global => {},
: aggs => {: filtered => {: filter => {: and => [{: range => {: created_at => {: gte => Mon,
01 Aug 2016 00: 00: 00 UTC + 00: 00,
: lt => Mon,
31 Jul 2017 00: 00: 00 UTC + 00: 00
}
}
}, {: terms => {: pupil_id => [1042]
}
}]
},
: aggs => {: categories => {: terms => {: field => "category"
}
},
: topic_ids => {: terms => {: field => "topic_id"
}
},
: learning_objective_ids => {: terms => {: field => "learning_objective_id"
}
},
: completed_activities => {: terms => {: field => : pupil_id
},
: aggs => {: activities => {: filter => {: and => [{: terms => {: category => [0, 1, 2, 3]
}
}]
}
}
}
}
}
}
}
}
}
} >> , @options = # < ReportOptions: 0x007fc96b663258 @search = # < PupilCreditSearch: 0x007fc961801308 @interval = : month, @page = 1, @per = 25, @pupil_id = [1042], @date_range = {: from => Mon,
01 Aug 2016 00: 00: 00 UTC + 00: 00,
: to => Mon,
31 Jul 2017 00: 00: 00 UTC + 00: 00
}, @queries = [# < Search::Query: 0x007fc964791bb8 @query = nil, @fields = [], @type = : multi_match, @options = {: fields => [],
: type => : cross_fields
} > ], @filters = [# < Search::Filter: 0x007fc964756db0 @name = : pupil_id, @value = [1042], @type = : terms, @options = {} > ], @aggregations = {: years_created => # < Search::Aggregation: 0x007fc9647a32f0 @type = : date_histogram,
@field = : created_at,
@options = {: field => : created_at,
: type => : date_histogram,
: params => {: interval => : year
}
} > ,
: months_created => # < Search::Aggregation: 0x007fc9647a30c0 @type = : date_histogram,
@field = : created_at,
@options = {: field => : created_at,
: type => : date_histogram,
: params => {: interval => : month
}
} > ,
: date_ranges => # < Search::Aggregation: 0x007fc9647a2800 @type = : date_range,
@field = : created_at,
@options = {: field => : created_at,
: type => : date_range,
: params => {: keyed => true,
: ranges => [{: from => "now/w",
: to => "now+1w/w",
: key => : this_week
}, {: from => "now/M",
: to => "now+1M/M",
: key => : this_month
}, {: from => "now-1w/w",
: to => "now-2w/w",
: key => : last_week
}, {: from => "now-1M/M",
: to => "now-2M/M",
: key => : last_month
}, {: from => "2016-09-01",
: to => "2017-08-31",
: key => : academic_year
}]
}
} > ,
: groups => # < Search::Aggregation: 0x007fc9647a2260 @type = : terms,
@field = : pupil_id,
@options = {: aggs => {: all_dates => # < Search::Aggregation: 0x007fc9647a22d8 @type = : date_histogram,
@field = : created_at,
@options = {: params => {: interval => : month
},
: aggs => {: total_points => # < Search::Aggregation: 0x007fc9647a2440 @type = : sum,
@field = : points,
@options = {} > ,
: running_total => # < Search::Aggregation: 0x007fc9647a2350 @type = : cumulative_sum,
@field = nil,
@options = {: params => {: buckets_path => "total_points"
}
} >
}
} >
}
} > ,
: options => # < Search::Aggregation: 0x007fc9647a1518 @type = : global,
@field = nil,
@options = {: aggs => {: filtered => # < Search::Aggregation: 0x007fc9647a1590 @type = : filter,
@field = nil,
@options = {: params => {: and => [{: range => {: created_at => {: gte => Mon,
01 Aug 2016 00: 00: 00 UTC + 00: 00,
: lt => Mon,
31 Jul 2017 00: 00: 00 UTC + 00: 00
}
}
}, {: terms => {: pupil_id => [1042]
}
}]
},
: aggs => {: categories => # < Search::Aggregation: 0x007fc9647a1b80 @type = : terms,
@field = "category",
@options = {: ignore => true
} > ,
: topic_ids => # < Search::Aggregation: 0x007fc9647a19a0 @type = : terms,
@field = "topic_id",
@options = {: ignore => true
} > ,
: learning_objective_ids => # < Search::Aggregation: 0x007fc9647a17c0 @type = : terms,
@field = "learning_objective_id",
@options = {: ignore => true
} > ,
: completed_activities => # < Search::Aggregation: 0x007fc9647a1608 @type = : terms,
@field = : pupil_id,
@options = {: aggs => {: activities => # < Search::Aggregation: 0x007fc9647a1680 @type = : filter,
@field = nil,
@options = {: params => {: and => [{: terms => {: category => [0, 1, 2, 3]
}
}]
}
} >
}
} >
}
} >
}
} >
}, @request = # < Search::Request: 0x007fc964753548 @params = {: query => {: bool => {: must => [{: match_all => {}
}],
: filter => [{: terms => {: pupil_id => [1042]
}
}]
}
},
: aggs => {: years_created => {: date_histogram => {: field => : created_at,
: interval => : year
}
},
: months_created => {: date_histogram => {: field => : created_at,
: interval => : month
}
},
: date_ranges => {: date_range => {: field => : created_at,
: keyed => true,
: ranges => [{: from => "now/w",
: to => "now+1w/w",
: key => : this_week
}, {: from => "now/M",
: to => "now+1M/M",
: key => : this_month
}, {: from => "now-1w/w",
: to => "now-2w/w",
: key => : last_week
}, {: from => "now-1M/M",
: to => "now-2M/M",
: key => : last_month
}, {: from => "2016-09-01",
: to => "2017-08-31",
: key => : academic_year
}]
}
},
: groups => {: terms => {: field => : pupil_id
},
: aggs => {: all_dates => {: date_histogram => {: field => : created_at,
: interval => : month
},
: aggs => {: total_points => {: sum => {: field => : points
}
},
: running_total => {: cumulative_sum => {: buckets_path => "total_points"
}
}
}
}
}
},
: options => {: global => {},
: aggs => {: filtered => {: filter => {: and => [{: range => {: created_at => {: gte => Mon,
01 Aug 2016 00: 00: 00 UTC + 00: 00,
: lt => Mon,
31 Jul 2017 00: 00: 00 UTC + 00: 00
}
}
}, {: terms => {: pupil_id => [1042]
}
}]
},
: aggs => {: categories => {: terms => {: field => "category"
}
},
: topic_ids => {: terms => {: field => "topic_id"
}
},
: learning_objective_ids => {: terms => {: field => "learning_objective_id"
}
},
: completed_activities => {: terms => {: field => : pupil_id
},
: aggs => {: activities => {: filter => {: and => [{: terms => {: category => [0, 1, 2, 3]
}
}]
}
}
}
}
}
}
}
}
}
}
The problem is with one of the aggregations, namely:
:filter => { :and => [...] }
...which leads me to conclusion that you actually may be running elasticsearch 5 and not 2.4, on your machine, because this syntax got dropped in version 5 in favour of:
:filter => { :bool => { :must: [...] } }
Verify the elasticsearch version with curl localhost:9200
(or the actual host/port your app is connecting to).
这篇关于ElasticSearch-格式错误的查询(RoR)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!