我想获取相应特定字段的所有数据,并有弹性搜索的响应。{"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错误显示:{ 错误:[illegal_argument_exception] 请求 [/_search] 包含无法识别的参数:[查询]请建议我如何解决此类问题。
2 回答
猛跑小猪
TA贡献1858条经验 获得超8个赞
您应该在 下指定您的字段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);
});
添加回答
举报
0/150
提交
取消