【发布时间】:2020-05-29 08:11:57
【问题描述】:
我正在尝试获取具有以下字段的项目列表:resellable: true。
这是我可以访问的数据集:my-domain.com/_all/listings/_search
{
"took" : 1,
"timed_out" : false,
"_shards" : {
"total" : 5,
"successful" : 5,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 4,
"relation" : "eq"
},
"max_score" : 1.0,
"hits" : [
{
"_index" : "collectibles",
"_type" : "listing",
"_id" : "SseZfNbpdpBxc3O",
"_score" : 1.0,
"_source" : {
"data" : {
"resellable" : true,
"active" : true,
"description" : "<p>1234 123 123 123</p>",
"title" : "2134",
"has_store" : true,
"createdAt" : "Wed May 27 2020 04:23:18 GMT+0000 (Coordinated Universal Time)",
"apiURL" : "kJ9zsIsdQG8TZrRfPco4",
"id" : "SseZfNbpdpBxc3O",
"state" : "PENDING",
"amount" : "21",
}
}
}
}
我的查询是使用*NodeJS and ElasticSearch.js*
let results = await client.search({
index: params.category,
type: "listing",
body: {
query: {
multi_match: {
query: true,
fields: ['resellable', 'active'],
type: 'best_fields',
}
}
}
})
回复总是no hits。我试过match,我试过没有best_fields,它似乎与值不匹配。
我在这里做错了什么?您还需要做些什么来查询_source.data 级别的项目吗?
ElasticSearch version: 7.4
【问题讨论】:
-
'resellable', 'active' 应该是 'data.resellable', data.'active'。如果您将查看您的输出可转售和活动以及部分数据字段 "_source" : { "data" : { "resellable" : true 或者您需要在索引时更正文档结构(删除数据)
-
@jaspreetchahal 是的,做到了。谢谢你。为什么只有“data.active”而不是“_source.data.active”?
-
_source 是 Elastisearch 的一个内部字段,包含所有字段,我们没有明确添加,所以不需要指定它
标签: node.js elasticsearch elasticsearch-query booleanquery