我有location以下屬性的索引。檔案通過entityId和關聯parentEntityId,因此存在分層資料。還有一個entityPath欄位包含當前檔案一直到根檔案的路徑。
有人可以指導如何在給定 entityId 的情況下獲取所有子 entityId 嗎?
PUT location
{
"mappings": {
"properties": {
"entityId": {"type": "text"},
"entityType": {"type": "text"},
"entityTypeId": {"type": "text"},
"resellerMSISDN": {"type": "text"},
"parentEntityId": {"type": "text"},
"entityName": {"type": "text"},
"entityPath": {"type": "text"},
"snic_category": {"type": "text"},
"address": {"type": "object"},
"location": {"type": "geo_point"},
"createdAt": {"type": "date"},
"updatedAt": {"type": "date"}
}
}
}
以下是示例檔案:
{
"_index" : "location",
"_type" : "_doc",
"_id" : "UyJgTX4BCWiVeWu9nnuM",
"_score" : 1.0,
"_source" : {
"entityId" : "FranchisesShop1",
"entityType" : "Franchises Shop",
"entityTypeId" : "franchisesshop",
"resellerMSISDN" : "254714410000",
"parentEntityId" : "OPERATOR",
"entityName" : "FranchisesShop 1",
"entityPath" : "OPERATOR/FranchisesShop1",
"address" : {
"street" : null,
"zip" : null,
"city" : null,
"country" : "Kenya",
"phone" : null,
"fax" : null,
"homepage" : null,
"email" : null
}
}
},
{
"_index" : "location",
"_type" : "_doc",
"_id" : "VCJgTX4BCWiVeWu9nnuM",
"_score" : 1.0,
"_source" : {
"entityId" : "ShopStaff1-1",
"entityType" : "Franchises Shop Staff",
"entityTypeId" : "shopstaff",
"resellerMSISDN" : "254714410100",
"parentEntityId" : "FranchisesShop1",
"entityName" : "ShopStaff 1",
"entityPath" : "OPERATOR/FranchisesShop1/ShopStaff1-1",
"address" : {
"street" : null,
"zip" : null,
"city" : null,
"country" : "Kenya",
"phone" : null,
"fax" : null,
"homepage" : null,
"email" : null
}
}
},
{
"_index" : "location",
"_type" : "_doc",
"_id" : "VSJgTX4BCWiVeWu9nnuM",
"_score" : 1.0,
"_source" : {
"entityId" : "ThirdPartyAgent1",
"entityType" : "Third Party Agents",
"entityTypeId" : "3pl_agents",
"resellerMSISDN" : "254714510000",
"parentEntityId" : "OPERATOR",
"entityName" : "ThirdPartyAgent 1",
"entityPath" : "OPERATOR/ThirdPartyAgent1",
"address" : {
"street" : null,
"zip" : null,
"city" : null,
"country" : "Kenya",
"phone" : null,
"fax" : null,
"homepage" : null,
"email" : null
}
}
},
{
"_index" : "location",
"_type" : "_doc",
"_id" : "ViJgTX4BCWiVeWu9nnuM",
"_score" : 1.0,
"_source" : {
"entityId" : "ThirdPartyAgentStaff1-1",
"entityType" : "Third Party Agents Staff",
"entityTypeId" : "3pl_agents_staff",
"resellerMSISDN" : "254714510100",
"parentEntityId" : "ThirdPartyAgent1",
"entityName" : "ThirdPartyAgentStaff 1",
"entityPath" : "OPERATOR/ThirdPartyAgent1/ThirdPartyAgentStaff1-1",
"address" : {
"street" : null,
"zip" : null,
"city" : null,
"country" : "Kenya",
"phone" : null,
"fax" : null,
"homepage" : null,
"email" : null
}
}
},
{
"_index" : "location",
"_type" : "_doc",
"_id" : "VyJgTX4BCWiVeWu9nnuM",
"_score" : 1.0,
"_source" : {
"entityId" : "Director2",
"entityType" : "Director",
"entityTypeId" : "director",
"resellerMSISDN" : "254714020000",
"parentEntityId" : "OPERATOR",
"entityName" : "Director 2",
"entityPath" : "OPERATOR/Director2",
"address" : {
"street" : null,
"zip" : null,
"city" : null,
"country" : "Kenya",
"phone" : null,
"fax" : null,
"homepage" : null,
"email" : null
}
}
},
{
"_index" : "location",
"_type" : "_doc",
"_id" : "WCJgTX4BCWiVeWu9nnuM",
"_score" : 1.0,
"_source" : {
"entityId" : "HoD2-1",
"entityType" : "Regional HoD",
"entityTypeId" : "hod",
"resellerMSISDN" : "254714021000",
"parentEntityId" : "Director2",
"entityName" : "HoD 1",
"entityPath" : "OPERATOR/Director2/HoD2-1",
"address" : {
"street" : "",
"zip" : null,
"city" : "",
"country" : "Kenya",
"phone" : null,
"fax" : null,
"homepage" : null,
"email" : "[email protected]"
},
"snic_category" : "Dealer"
}
},
{
"_index" : "location",
"_type" : "_doc",
"_id" : "WSJgTX4BCWiVeWu9nnuM",
"_score" : 1.0,
"_source" : {
"entityId" : "RSM2-1-1",
"entityType" : "Regional Sales Manager",
"entityTypeId" : "rsm",
"resellerMSISDN" : "254714021100",
"parentEntityId" : "HoD2-1",
"entityName" : "RSM 1",
"entityPath" : "OPERATOR/Director2/HoD2-1/RSM2-1-1",
"address" : {
"street" : null,
"zip" : null,
"city" : null,
"country" : "Kenya",
"phone" : null,
"fax" : null,
"homepage" : null,
"email" : null
}
}
},
{
"_index" : "location",
"_type" : "_doc",
"_id" : "WiJgTX4BCWiVeWu9nnuM",
"_score" : 1.0,
"_source" : {
"entityId" : "ASM2-1-1-1",
"entityType" : "Area Sales Manager",
"entityTypeId" : "asm",
"resellerMSISDN" : "254714021110",
"parentEntityId" : "RSM2-1-1",
"entityName" : "ASM 1",
"entityPath" : "OPERATOR/Director2/HoD2-1/RSM2-1-1/ASM2-1-1-1",
"address" : {
"street" : "2433",
"zip" : null,
"city" : "lhr",
"country" : "Kenya",
"phone" : null,
"fax" : null,
"homepage" : null,
"email" : "[email protected]"
},
"snic_category" : "Dealer"
}
},
{
"_index" : "location",
"_type" : "_doc",
"_id" : "WyJgTX4BCWiVeWu9nnuM",
"_score" : 1.0,
"_source" : {
"entityId" : "TDR2-1-1-1-1",
"entityType" : "Trade Dealer Representative",
"entityTypeId" : "tdr",
"resellerMSISDN" : "254714021111",
"parentEntityId" : "ASM2-1-1-1",
"entityName" : "TDR 1",
"entityPath" : "OPERATOR/Director2/HoD2-1/RSM2-1-1/ASM2-1-1-1/TDR2-1-1-1-1",
"address" : {
"street" : "111 wall street",
"zip" : null,
"city" : "lahore",
"country" : "Kenya",
"phone" : null,
"fax" : null,
"homepage" : null,
"email" : "[email protected]"
},
"snic_category" : "Agent"
}
},
{
"_index" : "location",
"_type" : "_doc",
"_id" : "XCJgTX4BCWiVeWu9nnuM",
"_score" : 1.0,
"_source" : {
"entityId" : "FranchisesShop2",
"entityType" : "Franchises Shop",
"entityTypeId" : "franchisesshop",
"resellerMSISDN" : "254714420000",
"parentEntityId" : "OPERATOR",
"entityName" : "FranchisesShop 2",
"entityPath" : "OPERATOR/FranchisesShop2",
"address" : {
"street" : null,
"zip" : null,
"city" : null,
"country" : "Kenya",
"phone" : null,
"fax" : null,
"homepage" : null,
"email" : null
}
}
}
uj5u.com熱心網友回復:
在 Elasticsearch 中使用您當前的資料結構無法做到這一點。
有兩種選擇:
- 使用多級嵌套資料結構并在索引時對其建模
- 在應用程式中使用遞回呼叫
uj5u.com熱心網友回復:
創建自定義analyzer即slash-analyzer用于分析entityPath欄位。
修改索引創建
PUT location
{
"settings": {
"analysis": {
"analyzer": {
"slash_analyzer": {
"type": "pattern",
"pattern": "/"
}
}
}
},
"mappings": {
"properties": {
"entityId": {"type": "text"},
"entityType": {"type": "text"},
"entityTypeId": {"type": "text"},
"resellerMSISDN": {"type": "text"},
"parentEntityId": {"type": "text"},
"entityName": {"type": "text"},
"entityPath": {
"type": "text",
"analyzer": "slash_analyzer"
},
"snic_category": {"type": "text"},
"address": {"type": "object"},
"location": {"type": "geo_point"},
"createdAt": {"type": "date"},
"updatedAt": {"type": "date"}
}
}
}
下面是獲取 FranchisesShop1 的所有子項的搜索查詢,包括它自己。
GET location/_search
{
"query": {
"match": {
"entityPath": {
"query": "FranchisesShop1"
}
}
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/414397.html
標籤:
