gpt4 book ai didi

javascript - 如何获取elasticsearch索引中的特定文档

转载 作者:行者123 更新时间:2023-12-01 00:36:14 25 4
gpt4 key购买 nike

我想获取对应特定字段的所有数据,并得到elasticsearch的响应。

{
"took": 2,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"skipped": 0,
"failed": 0
},
"hits": {
"total": {
"value": 35,
"relation": "eq"
},
"max_score": 0.44183275,
"hits": [
{
"_index": "allevents",
"_type": "_doc",
"_id": "jQPDaG0BcOh3oggcguoV",
"_score": 0.44183275,
"_source": {
"category": "sessions",
"contentid": "KqRLj2lWZ3",
"clientname": "omkarpathlab",
------------------
}]

我尝试了搜索功能,但它返回了错误。

var elasticsearch = require('elasticsearch');
var client = new elasticsearch.Client({
host: 'aaa',
log: 'trace',
apiVersion: '7.1'
});

client.search({
"size": 20,
"query": {
"query_string": {
"default_field": "clientname",
"query": "omkarlab"
}
}
}).then((res) => {
console.log("resultData", res);
}, (err) => {
console.log("err", err);
});
enter code here

错误显示:

{ Error: [illegal_argument_exception] request [/_search] contains unrecognized parameter: [query]

请建议我如何解决此类问题。

最佳答案

您应该在 default_field 下指定您的字段,而不是您要查找的值。在您的情况下,您尝试查询的字段是 clientname,您要查找的值是 omkarpathlab。因此您的查询应如下所示:

"query": {
"query_string": {
"default_field": "clientname",
"query": "omkarpathlab"
}
}

编辑。但是您在 body 属性内的查询:

client.search({
"size": 20,
"body": {
"query": {
"query_string": {
"default_field": "clientname",
"query": "omkarlab"
}
}
}
}).then((res) => {
console.log("resultData", res);
}, (err) => {
console.log("err", err);
});

关于javascript - 如何获取elasticsearch索引中的特定文档,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58114835/

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