elasticsearch 从elasticsearch Node.js客户端v7.2.0获取聚合查询的错误响应
我正在使用Node.js client v7.2.0 for elasticsearch对嵌套对象发送一个嵌套聚合查询。在Node.js客户机上执行查询时,我获取的是该索引的所有记录,而不是聚合过滤的结果。使用kibana或curl执行相同的查询可以得到预期的结果 问题:-elasticsearch 从elasticsearch Node.js客户端v7.2.0获取聚合查询的错误响应,elasticsearch,kibana,elasticsearch,Kibana,我正在使用Node.js client v7.2.0 for elasticsearch对嵌套对象发送一个嵌套聚合查询。在Node.js客户机上执行查询时,我获取的是该索引的所有记录,而不是聚合过滤的结果。使用kibana或curl执行相同的查询可以得到预期的结果 问题:- const client = new Client({ node: 'http://localhost:9200' }); let body = { "size": 0, "query": { "boo
const client = new Client({ node: 'http://localhost:9200' });
let body = {
"size": 0,
"query": {
"bool": {
"must": [
{
"nested": {
"path": "doc.parentKey",
"query": {
"bool": {
"must": [
{
"term": {
"doc.parentKey.name.keyword": "Name1"
}
}
]
}
}
}
},
{
"term": {
"doc.owner.keyword": "0aa7b933-eab1-4939-b4d2-38c2d0602cba"
}
}
]
}
},
"aggs": {
"parentKey": {
"nested": {
"path": "doc.parentKey"
},
"aggs": {
"response": {
"aggs": {
"name": {
"terms": {
"field": "doc.parentKey.name.keyword"
},
"aggs": {
"value": {
"terms": {
"field": "doc.parentKey.value.keyword"
}
}
}
}
},
"filter": {
"term": {
"doc.parentKey.name.keyword": "Name1"
}
}
}
}
}
}
}
let {body: response} = await client.search({index: 'test-index', body});
预期结果(从kibana和curl获得)
来自Node.js客户端的结果
{
"body": {
"took": 1277,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"skipped": 0,
"failed": 0
},
"hits": {
"total": {
"value": 10000,
"relation": "gte"
},
"max_score": 1,
"hits": [
{
"_index": "indexName",
"_type": "_doc",
"_id": "2f0e4524-1203-40a6-8527-aa980fc349a7[8196858]",
"_score": 1,
"_source": {
"doc": {
"owner": "059d2569-f268-417f-906b-cbed1f6fbcec",
"parentKey": [
{
"value": "Value3",
"name": "Name3"
},
{
"value": "Value4",
"name": "Name4"
}
]
},
"@version": "1",
"doc_as_upsert": true,
"@timestamp": "2019-07-31T09:29:27.644Z"
}
},
{
"_index": "indexName",
"_type": "_doc",
"_id": "6f5652a3-8b33-4c53-8bea-316e8ab1b8c5[8201864]",
"_score": 1,
"_source": {
"doc": {
"owner": "71a83599-1751-4fa4-896a-46b644f29a50"
"parentKey": [
{
"value": "Value1",
"name": "Name1"
},
{
"value": "Value2",
"name": "Name2"
}
]
},
"@version": "1",
"doc_as_upsert": true,
"@timestamp": "2019-07-31T09:29:33.795Z"
}
}
]
}
},
"statusCode": 200,
"headers": {
"content-type": "application/json; charset=UTF-8",
"date": "Thu, 08 Aug 2019 13:27:15 GMT",
"server": "nginx/1.12.2",
"content-length": "113899",
"connection": "keep-alive"
},
"warnings": null,
"meta": {
"context": null,
"request": {
"params": {
"method": "GET",
"path": "/indexName/_search",
"body": "",
"querystring": "",
"headers": {
"User-Agent": "elasticsearch-js/7.3.0 (linux 3.10.0-862.9.1.el7.x86_64-x64; Node.js v8.9.4)",
"Content-Type": "application/json",
"Content-Length": "0"
},
"timeout": 30000
},
"options": {
"size": 0,
"aggs": {
"parentKey": {
"nested": {
"path": "doc.parentKey"
},
"aggs": {
"response": {
"aggs": {
"name": {
"terms": {
"field": "doc.parentKey.name.keyword"
},
"aggs": {
"value": {
"terms": {
"field": "doc.parentKey.value.keyword"
}
}
}
}
},
"filter": {
"term": {
"doc.parentKey.name.keyword": "63bb04a3eb41417e8d0e61e074293581"
}
}
}
}
}
},
"warnings": null
},
"id": 1
},
"name": "elasticsearch-js",
"connection": {
"url": "http://elasticsearch",
"id": "http://elasticsearch",
"headers": {},
"deadCount": 0,
"resurrectTimeout": 0,
"_openRequests": 0,
"status": "alive",
"roles": {
"master": true,
"data": true,
"ingest": true,
"ml": false
}
},
"attempts": 0,
"aborted": false
}
}
来自Node.js客户端的响应被截断(响应由hits.hits数组中的10个对象组成,我们也可以通过运行match_all来获取该索引)
非常感谢您提供的任何帮助。我认为您的
搜索呼叫中缺少一个键:
let {body: response} = await client.search({index: 'test-index', body: body});
^
|
add the body key
你能展示你正在使用的node.js代码吗?我已经更新了这个问题。请现在检查,即使没有它也可以用。使用ES6中的对象属性速记,{body:body}可以像{body}一样简单地传递。
let {body: response} = await client.search({index: 'test-index', body: body});
^
|
add the body key