根据上述问题,我用Val给定的脚本进行的elasticsearch查询在最后一周之前都可以正常工作。我们已经升级了ES版本,但突然停止了工作。
{
"size": 0,
"aggs": {
"count": {
"terms": {
"script": "doc.billingSequence.value as Integer", <--- transform the terms to integers
"order": {
"_term": "asc"
},
"value_type": "integer", <--- consider the terms as integer when sorting
"size": 10
}
}
}
}
现在突然我的ES停止使用脚本中包含“ as Integer”的代码。任何人都可以检查和帮助。
[DEBUG] 2015-10-26 10:00:13,907 org.elasticsearch.action.search.type - [Eson the Searcher] [owce_assets][4], node[aNnn7tvHRi6tCkOA-RU2nw], [P], s[STARTED]: Failed to execute [org.elasticsearch.action.search.SearchRequest@123872f5] lastShard [true]
org.elasticsearch.search.SearchParseException: [owce_assets][4]: from[0],size[100]: Parse Failure [Failed to parse source [{"from":0,"size":100,"aggregations_binary":"ewoJCQkJCQkiY291bnQiOiB7IAoJCQkJCQkJInRlcm1zIjogewoJCQkJCQkJCSJzY3JpcHQiOiJkb2MuYmlsbGluZ1NlcXVlbmNlLnZhbHVlIGFzIEludGVnZXIiLAoJCQkJCQkJCSJvcmRlciI6IHsKCQkJCQkJCQkgICJfdGVybSI6ICJhc2MiCgkJCQkJCQkJfSwKCQkJCQkJCQkidmFsdWVfdHlwZSI6ICJpbnRlZ2VyIiwgICAgIAoJCQkJCQkic2l6ZSI6IDIwCgkJCQkJCQkJCgkJCQkJCQkgfQoJCQkJCQl9CgkJCQkJfQ=="}]]
at org.elasticsearch.search.SearchService.parseSource(SearchService.java:634)
at org.elasticsearch.search.SearchService.createContext(SearchService.java:507)
at org.elasticsearch.search.SearchService.createAndPutContext(SearchService.java:480)
at org.elasticsearch.search.SearchService.executeQueryPhase(SearchService.java:252)
at org.elasticsearch.search.action.SearchServiceTransportAction.sendExecuteQuery(SearchServiceTransportAction.java:202)
at org.elasticsearch.action.search.type.TransportSearchQueryThenFetchAction$AsyncAction.sendExecuteFirstPhase(TransportSearchQueryThenFetchAction.java:80)
at org.elasticsearch.action.search.type.TransportSearchTypeAction$BaseAsyncAction.performFirstPhase(TransportSearchTypeAction.java:216)
at org.elasticsearch.action.search.type.TransportSearchTypeAction$BaseAsyncAction.performFirstPhase(TransportSearchTypeAction.java:203)
at org.elasticsearch.action.search.type.TransportSearchTypeAction$BaseAsyncAction$2.run(TransportSearchTypeAction.java:186)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:744)
Caused by: [Error: unknown class or illegal statement: org.elasticsearch.common.mvel2.ParserContext@7915fb96]
[Near : {... doc.billingSequence.value as Integer ....}]
^
我尝试了给定的查询,现在它抛出以下异常。
[DEBUG] 2015-10-26 10:33:01,912 org.elasticsearch.action.search.type - [Eson the Searcher] [owce_assets][4], node[aNnn7tvHRi6tCkOA-RU2nw], [P], s[STARTED]: Failed to execute [org.elasticsearch.action.search.SearchRequest@66accd25] lastShard [true]
org.elasticsearch.search.SearchParseException: [owce_assets][4]: from[0],size[100]: Parse Failure [Failed to parse source [{"from":0,"size":100,"aggregations_binary":"ewoiY291bnQiOiB7CiAgInRlcm1zIjogewogICAgInNjcmlwdCI6ICJkb2MuYmlsbGluZ1NlcXVlbmNlLnZhbHVlIGFzIEludGVnZXIiLAogICAgIm9yZGVyIjogewogICAgICAiX3Rlcm0iOiAiYXNjIgogICAgfSwKICAgICJ2YWx1ZV90eXBlIjogImludGVnZXIiLAogICAgInNpemUiOiAxMCwKICAgICJsYW5nIjogImdyb292eSIgICAgICAgICAgICAKICB9Cn0KfQ=="}]]
at org.elasticsearch.search.SearchService.parseSource(SearchService.java:634)
at org.elasticsearch.search.SearchService.createContext(SearchService.java:507)
at org.elasticsearch.search.SearchService.createAndPutContext(SearchService.java:480)
at org.elasticsearch.search.SearchService.executeQueryPhase(SearchService.java:252)
at org.elasticsearch.search.action.SearchServiceTransportAction.sendExecuteQuery(SearchServiceTransportAction.java:202)
at org.elasticsearch.action.search.type.TransportSearchQueryThenFetchAction$AsyncAction.sendExecuteFirstPhase(TransportSearchQueryThenFetchAction.java:80)
at org.elasticsearch.action.search.type.TransportSearchTypeAction$BaseAsyncAction.performFirstPhase(TransportSearchTypeAction.java:216)
at org.elasticsearch.action.search.type.TransportSearchTypeAction$BaseAsyncAction.performFirstPhase(TransportSearchTypeAction.java:203)
at org.elasticsearch.action.search.type.TransportSearchTypeAction$BaseAsyncAction$2.run(TransportSearchTypeAction.java:186)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:744)
Caused by: org.elasticsearch.ElasticsearchIllegalArgumentException: script_lang not supported [groovy]
at org.elasticsearch.script.ScriptService.compile(ScriptService.java:143)
at org.elasticsearch.script.ScriptService.search(ScriptService.java:163)
at
org.elasticsearch.search.aggregations.bucket.terms.TermsParser.parse(TermsParser.java:202)
at org.elasticsearch.search.aggregations.AggregatorParsers.parseAggregators(AggregatorParsers.java:114)
at org.elasticsearch.search.aggregations.AggregatorParsers.parseAggregators(AggregatorParsers.java:77)
at org.elasticsearch.search.aggregations.AggregationParseElement.parse(AggregationParseElement.java:60)
at org.elasticsearch.search.aggregations.AggregationBinaryParseElement.parse(AggregationBinaryParseElement.java:42)
at org.elasticsearch.search.SearchService.parseSource(SearchService.java:622)
... 11 more
我作为参数传递的查询是:
{
"count": {
"terms": {
"script": "Integer.parseInt(doc.billingSequence.value)",
"order": {
"_term": "asc"
},
"value_type": "integer",
"size": 20
}
}
}
由于我的索引器在该billingSequence
字段中包含1、2、4、6、14个值。但是执行完此查询后,我只得到2、4、6的结果。
确切地说,我的代码如下所示。
<mix:variable name="aggregations" as="xs:string">
<mix:option name="disable-expression-parsing" value="true"/>
{
"fatal_errors": {
"filter": {
"and":[
<!-- Filter by date (if given). Value should be send as "`DATE#" and the period should be in Filter data(<Filter name="field_name" value="`DATE#">1d</Filter>).-->
<mix:for-each select="//Date">
<mix:if test="$comma">,</mix:if>
{ "range": {
"<mix:value-of select='./@name'/>": {
"gte": "now-<mix:value-of select='./@value'/>",
"lt": "now"
}
}
}
<mix:global-variable name="comma" select="true()" as="xs:boolean"/>
</mix:for-each>
<!-- Filter all the not nulls or blanks in a field (if given). Value should be send as "`NOT_NULL#" (<Filter name="field_name" value="`NOT_NULL#"></Filter>).-->
<mix:for-each select="//NotNull">
<mix:if test="$comma">,</mix:if>
{
"not":
{
"term":{
"<mix:value-of select='./@name'/>":""
}
}
}
<mix:global-variable name="comma" select="true()" as="xs:boolean"/>
</mix:for-each>
<mix:for-each select="//FitlerTerm">
<mix:if test="$comma">,</mix:if>
{
"term":{
"<mix:value-of select='./@name'/>":"<mix:value-of select='./@value'/>"
}
}
<mix:global-variable name="comma" select="true()" as="xs:boolean"/>
</mix:for-each>
]
},
"aggs": {
"count": {
"terms": {
"script": "Integer.parseInt(doc.billingSequence.value)",
"order": {
"_term": "asc"
},
"value_type": "integer",
"size": 20
}
}
}
}
}
<mix:option name="disable-expression-parsing" value="false"/>
</mix:variable>
在这里,我通过了一个带有过滤器的聚合。我的过滤器工作正常,在聚合的地方,我遇到了问题。请检查并做有需要的事情。
看来您正在使用mvel
脚本。您只需要指定要使用的名称即可groovy
。
{
"size": 0,
"aggs": {
"count": {
"terms": {
"script": "doc.billingSequence.value as Integer",
"order": {
"_term": "asc"
},
"value_type": "integer",
"size": 10,
"lang": "groovy" <--- add this line
}
}
}
}
还要确保将其包括在项目依赖项中,因为默认情况下不包括此项:
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
<version>2.4.0</version>
<scope>compile</scope>
<optional>true</optional>
</dependency>
更新
如果您确实不能使用Groovy,则可以坚持使用MVEL并使用MVEL类型转换:
{
"size": 0,
"aggs": {
"count": {
"terms": {
"script": "Integer.parseInt(doc.billingSequence.value)", <--- change this line
"order": {
"_term": "asc"
},
"value_type": "integer",
"size": 10
}
}
}
}
问题内容: 我有一个索引器,其中包含一个名为“ billingSequence”的字段。映射中该字段的数据类型为String,并且该字段的每个记录的值可以是1到30之间的一个。我使用此字段进行聚合,并且在尝试对_terms进行排序时,该字段的排序不正确是字符串类型。 上述聚合排序的结果是-1 11 12 13 14 15 16 17 18 19 2 3 4 5等。 预期结果是-1 2 3 4 5
问题内容: 我在使用Elasticsearch查询时遇到问题。我希望能够对结果进行排序,但是elasticsearch忽略了排序标签。这是我的查询: 但是,当我删除查询部分并仅发送排序标签时,它就可以工作。谁能指出正确的方法? 我还尝试了以下查询,这是我所拥有的完整查询: 设定值 对应 提前致谢! 问题答案: 文档中的 “标题” 字段是一个 分析的 字符串字段,也是一个多值字段,这意味着Elast
我想在多个字段上进行日期直方图/范围聚合,并将结果存储在其他集合/索引中。因此,我可以在小时范围内使用查询/聚合使doc_count和。 聚合如下: 结果不出所料: 假设我解析了响应,并尝试将结果存储在其他索引/集合中。 存储聚合结果的最佳方式是什么,这样我就可以进行其他查询/聚合,以求和不同小时范围之间的“doc_count”? 例如:在“2016-07-17t00:00.000z”-“2016
我的MongoDB数据库有一个结构 每个a文档都有一个带有bool值vield“result”。我进行聚合选择: 并得到一个结果: 如何计算字段“result”中值“true”和“false”的数量,并得到如下结果:
我已经在按\u score desc排序的查询部分中获得了所需的查询结果。现在我需要提取每个文档的3个字段。我想实现如下目标: 我刚刚试过: 1)使用折叠删除重复的值 但问题是它只会保留filed1的不同值,而忽略field 2和field 3的值。例如,我们有2条记录,如下所示: 使用此方法,我们只能获得一条记录,因为它们具有相同的field1值。我想要这三个字段的不同组合值。我们可以使用int
问题内容: 想象一下,我有两种记录:一个存储桶和一个项目,其中存储在存储桶中的项目,而存储桶中的项目可能相对较少(通常不超过4个,从不超过10个)。这些记录被压缩为一个(具有更多存储桶信息的项目),并放置在Elasticsearch中。我要解决的任务是通过依赖项属性的过滤查询一次找到500个存储桶(最大),其中包含所有相关项,而我受困于限制/抵消聚合。我该如何执行此类任务?我看到聚合使我可以控制相