gpt4 book ai didi

elasticsearch - 从 elasticsearch Node.js 客户端 v7.2.0 获取不正确的聚合查询响应

转载 作者:行者123 更新时间:2023-12-03 00:30:55 24 4
gpt4 key购买 nike

我正在使用用于 elasticsearch 的 Node.js 客户端 v7.2.0 在嵌套对象上发送嵌套聚合查询。在 Node.js 客户端上执行查询时,我得到了该索引的所有记录,而不是聚合的过滤结果。使用 kibana 或 curl 执行相同的查询会提供预期的结果。

询问 :-

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 获取)
{
"took" : 47,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 131,
"relation" : "eq"
},
"max_score" : null,
"hits" : [ ]
},
"aggregations" : {
"parentKey" : {
"doc_count" : 10218,
"response" : {
"doc_count" : 131,
"name" : {
"doc_count_error_upper_bound" : 0,
"sum_other_doc_count" : 0,
"buckets" : [
{
"key" : "Name1",
"doc_count" : 131,
"value" : {
"doc_count_error_upper_bound" : 0,
"sum_other_doc_count" : 0,
"buckets" : [
{
"key" : "Value1",
"doc_count" : 131
}
]
}
}
]
}
}
}
}
}

来自 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 来获得)

任何形式的帮助将不胜感激。

最佳答案

我认为您的 search 中缺少一个键。称呼:

let {body: response} = await client.search({index: 'test-index', body: body});
^
|
add the body key

关于elasticsearch - 从 elasticsearch Node.js 客户端 v7.2.0 获取不正确的聚合查询响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57414163/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com