elasticsearch - 无法在 Elastic Search 中检索嵌套对象
问题描述
这里是一个 ELK 菜鸟,最后一分钟有 ELK 任务交给我。
我们正在添加一个名为车辆索引的额外数据prospects
,以便用户可以搜索它。我可以将其添加prospects
到索引中,现在我无法prospects
在车辆索引中获取嵌套的 obj。我正在使用 Elastic Search & Kibana v6.8.11 和 elastic-search-rails gem 并检查了有关嵌套对象的文档。根据文档,我的搜索方法看起来是正确的。希望一些专家指出这里有什么问题,如果您需要更多信息,请告诉我。
这是假设索引 obj -
{
"_index" : "vehicles",
"_type" : "_doc",
"_id" : "3MZBxxxxxxx",
"_score" : 0.0,
"_source" : {
"vin" : "3MZBxxxxxxx",
"make" : "mazda",
"model" : "mazda3",
"color" : "unknown",
"year" : 2018,
"vehicle" : "2018 mazda mazda3",
"trim" : "grand touring",
"estimated_mileage" : null,
"dealership" : [
209
],
"current_owner_group_id" : null,
"current_owner_customer_id" : null,
"last_service_date" : null,
"last_service_revenue" : null,
"purchase_type" : [ ],
"in_service_date" : null,
"deal_headers" : [ ],
"services" : [ ],
"customers" : [ ],
"salesmen" : null,
"service_appointments" : [ ],
"prospects" : [
{
"first_name" : "Kammy",
"last_name" : "Maytag",
"name" : "Kammy Maytag",
"company_name" : null,
"emails" : [ ],
"phone_numbers" : [ ],
"address" : "31119 field",
"city" : "helen",
"state" : "keller",
"zip" : "81411",
"within_dealership_aoi_region" : true,
"dealership_ids" : [
209
],
"dealership_dppa_protected_ids" : [
209
],
"registration_id" : 12344,
"id" : 1054,
"prospect_source_id" : "12344",
"type" : "Prospect"
}
]
}
}
]
}
}
这是我试图得到它的方式 -
GET /vehicles/_search
{
"query": {
"bool": {
"must": { "match_all": {} },
"filter": [
{ "term": { "dealership": "209" } },
{
"nested": {
"path": "prospects",
"query": {
"bool": {
"must": [
{ "term": { "prospects.first_name": "Kammy" } },
{ "term": { "prospects.dealership": "209" } },
{ "term": { "prospects.type": "Prospect" } }
]
}
}
}
},
{ "bool": { "must_not": { "term": { "purchase_type": "Wholesale" } } } }
]
}
},
"sort": [{ "_doc": { "order": "asc" } }]
}
解决方案
我看到嵌套查询有两个问题:
- 您正在查询
prospects.dealership
,但示例文档仅显示prospects.dealership_ids
. 将查询更改为目标prospects.dealership_ids
。 - 更重要的是,您在and上使用
term
查询。我假设您的索引映射没有将它们定义为这意味着它们很可能是小写的(出于此处解释的原因),但正在寻找精确匹配。prospects.first_name
prospects.type
keywords
term
- 选项 1:使用
match
而不是term
. - 选项 2:更改
prospects.first_name
→prospects.first_name.keyword
并对.type
.
- 选项 1:使用
推荐阅读
- javascript - 浏览器中的事件循环如何同时处理事件队列、作业队列、渲染队列?
- python - 当屏幕被阻塞时,Spyder 停止运行
- typescript - TypeError...不是一个函数
- php - Laravel Eloquent 中的 MySQL 类型 CHAR 问题
- crystal-reports - 水晶报告中有什么方法可以用法语显示总价吗
- javascript - Fullcallendar v5.5.0 切换视图时如何连接不同的eventSource
- sql - Spark SQL根据列数据类型有条件地选择列
- rust - 像 `f64::from_str` 一样准确地计算 `n * 10^p`?
- python - 仅当单独列中的差异在 [-n, +n] 范围内时,才在公共列上加入两个 DataFrame
- sql - 我想在特定字符是sql中存在的字符之后提取一个字符串