【发布时间】:2019-08-10 03:31:01
【问题描述】:
这是一份文件
{
"Id": "1",
"Name": "Thing",
"Prices": [
{"CompanyId": "1", "Price": "11.11"},
{"CompanyId": "2", "Price": "12.12"},
{"CompanyId": "3", "Price": "13.13"}
这里是关联的 ElasticSearch 架构:
"Prices" : {
"type" : "nested",
"properties" : {
"CompanyId": {
"type" : "integer"
},
"Price" : {
"type" : "scaled_float",
"scaling_factor" : 100
}
}
}
如果用户购买CompantId = 3,那么供应商不希望他们能够看到CompanyId = 1 的优惠价格。
因此我需要使用源过滤器来删除所有CompanyId 不是3 的价格。
我发现这行得通。
"_source":{
"excludes": ["Prices.companyId.CompanyId"]
}
但我不明白如何或为什么。
它不可能工作,因为在整个 ElasticSearch 搜索 JSON 中的任何地方都没有提到所需的 CompanyId。
添加完整的搜索 JSON:
{
"query":{
"bool":{
"must":[
{
"match_all":{
}
}
],
"filter":{
"match":{
"PurchasingViews":6060
}
}
}
},
"size":20,
"aggs":{
"CompanyName.raw":{
"terms":{
"field":"CompanyName.raw",
"size":20,
"order":{
"_count":"desc"
}
}
}
},
"_source":{
"excludes":[
"PurchasingViews",
"ContractFilters",
"SearchField*",
"Keywords*",
"Menus*",
"Prices.companyId.CompanyId"
]
}
}
结果:
{
"took":224,
"timed_out":false,
"_shards":{
"total":5,
"successful":5,
"skipped":0,
"failed":0
},
"hits":{
"total":1173525,
"max_score":1.0,
"hits":[
{
"_index":"products_purchasing",
"_type":"product_purchasing",
"_id":"12787114",
"_score":1.0,
"_source":{
"CompanyName":"...",
"Prices":[
{
"CompanyId":1474,
"Price":697.3
}
],
"CompanyId":571057,
"PartNumber":"...",
"LongDescription_en":"...",
"Name_en":"...",
"DescriptionSnippet_en":"...",
"ProductId":9605985,
"Id":12787114
}
}
]
},
"aggregations":{
"CompanyName.raw":{
"doc_count_error_upper_bound":84,
"sum_other_doc_count":21078,
"buckets":[
{
"key":"...",
"doc_count":534039
}
]
}
}
}
【问题讨论】:
-
你能显示你发送的查询和你看到的结果吗?
-
你能把所有这些都添加到你的问题中吗,因为它更清晰,谢谢
-
刚刚发现过滤器巧合地将结果减少到只有一个价格的文档。所以问题仍然存在:我如何编写一个源过滤器来删除 CompanyId 不是 3 的所有价格。
标签: elasticsearch elasticsearch-query