弹性搜索中如何获取嵌套对象的数组计数
是否有人可以帮助我获得弹性搜索中嵌套对象的聚合计数,假设我的弹性搜索对象映射为:弹性搜索中如何获取嵌套对象的数组计数,
Warning: implode(): Invalid arguments passed in /data/phpspider/zhask/webroot/tpl/detail.html on line 45
,,是否有人可以帮助我获得弹性搜索中嵌套对象的聚合计数,假设我的弹性搜索对象映射为: { "employe": { "dynamic": "strict", "properties": { "empId":{ "type": "keyword" }, "entities": { "type": "nested" } } } } 实体是具有其他对象的数组类型。我想获得过滤项的实体数。 我尝试了一些弹性搜索查询,但不起作用 { "query": { "
{
"employe": {
"dynamic": "strict",
"properties": {
"empId":{
"type": "keyword"
},
"entities": {
"type": "nested"
}
}
}
}
实体是具有其他对象的数组类型。我想获得过滤项的实体数。
我尝试了一些弹性搜索查询,但不起作用
{
"query": {
"bool": {
"filter": [
{
"terms": {
"empId": [12121,2121212]
}
}
]
}
},
"size": 0,
"aggs": {
"entities_agg": {
"sum": {
"field": "entities",
"script": {
"inline": "doc['entities'].values.size()"
}
}
}
}
}
不能通过文档值访问嵌套数据,需要访问源文档,如下所示:
{
"query": {
"bool": {
"filter": [
{
"terms": {
"empId": [
12121,
2121212
]
}
}
]
}
},
"size": 0,
"aggs": {
"entities_agg": {
"sum": {
"script": {
"inline": "params._source.entities.size()"
}
}
}
}
}
不能通过文档值访问嵌套数据,需要访问源文档,如下所示:
{
"query": {
"bool": {
"filter": [
{
"terms": {
"empId": [
12121,
2121212
]
}
}
]
}
},
"size": 0,
"aggs": {
"entities_agg": {
"sum": {
"script": {
"inline": "params._source.entities.size()"
}
}
}
}
}
我得到这个错误{“type”:“script_exception”,“reason”:“runtime error”,“script_stack”:[“params.\u source.entities.size(),“^----HERE”],“script”:“params.\u source.entities.size(),“lang”:“无痛”,“由引起”:{“类型”:“null\u指针\u异常”,“原因”:null}}这可能是因为某些文档没有任何
实体
字段。这可能吗?好的,那么您使用的是哪个版本的ES?“版本”:{“编号”:“5.6.8”,“构建日期”:“2018-02-16T16:46:30.010Z”,“构建快照”:false,“lucene_版本”:“6.6.1”}好的,很好,很高兴这有帮助!我得到这个错误{“type”:“script_exception”,“reason”:“runtime error”,“script_stack”:[“params.\u source.entities.size(),“^----HERE”],“script”:“params.\u source.entities.size(),“lang”:“无痛”,“由引起”:{“类型”:“null\u指针\u异常”,“原因”:null}}这可能是因为某些文档没有任何实体
字段。这可能吗?好的,那么您使用的是哪个版本的ES?“版本”:{“编号”:“5.6.8”,“构建日期”:“2018-02-16T16:46:30.010Z”,“构建快照”:false,“lucene_版本”:“6.6.1”}好的,很好,很高兴这有帮助!