Json 具有动态键的Elasticsearch嵌套对象模式设计
尝试在Elasticsearch 7中索引JSON文件下方时收到以下错误 问题在于动态映射遇到太多的键。特别是将产品id列为对象的产品和术语,因此它们在json对象中成为唯一的实体Json 具有动态键的Elasticsearch嵌套对象模式设计,json,elasticsearch,dynamic,elastic-stack,Json,elasticsearch,Dynamic,Elastic Stack,尝试在Elasticsearch 7中索引JSON文件下方时收到以下错误 问题在于动态映射遇到太多的键。特别是将产品id列为对象的产品和术语,因此它们在json对象中成为唯一的实体 { "formatVersion": "v1.0", "disclaimer": "This pricing list is for informational purposes only. All prices are subject to the additional terms include
{
"formatVersion": "v1.0",
"disclaimer": "This pricing list is for informational purposes only. All prices are subject to the additional terms included in the pricing pages on http://aws.amazon.com. All Free Tier prices are also subject to the terms included at https://aws.amazon.com/free/",
"offerCode": "AmazonRedshift",
"version": "20200511174831",
"publicationDate": "2020-05-11T17:48:31Z",
"products": {
"KNVR5PFC54PXV76M": {
"sku": "KNVR5PFC54PXV76M",
"productFamily": "Compute Instance",
"attributes": {
"servicecode": "AmazonRedshift",
"location": "Africa (Cape Town)",
"locationType": "AWS Region",
"instanceType": "dc2.large",
"currentGeneration": "Yes",
"vcpu": "2",
"memory": "15 GiB",
"storage": "0.16TB SSD",
"io": "0.60 GB/s",
"usagetype": "AFS1-Node:dc2.large",
"operation": "RunComputeNode:0001",
"ecu": "7",
"servicename": "Amazon Redshift",
"usageFamily": "Dense Compute"
}
}
},
"terms": {
"OnDemand": {
"KNVR5PFC54PXV76M": {
"KNVR5PFC54PXV76M.JRTCKXETXF": {
"offerTermCode": "JRTCKXETXF",
"sku": "KNVR5PFC54PXV76M",
"effectiveDate": "2020-04-01T00:00:00Z",
"priceDimensions": {
"KNVR5PFC54PXV76M.JRTCKXETXF.6YS6EN2CT7": {
"rateCode": "KNVR5PFC54PXV76M.JRTCKXETXF.6YS6EN2CT7",
"description": "$0.357 per Redshift Dense Compute Large (DC2.L) Compute Node-hour (or partial hour)",
"beginRange": "0",
"endRange": "Inf",
"unit": "Hrs",
"pricePerUnit": {
"USD": "0.3570000000"
},
"appliesTo": []
}
},
"termAttributes": {}
}
}
},
"Reserved": {
"U4V6Y3USKUYCB6Q5": {
"U4V6Y3USKUYCB6Q5.6QCMYABX3D": {
"offerTermCode": "6QCMYABX3D",
"sku": "U4V6Y3USKUYCB6Q5",
"effectiveDate": "2016-05-31T23:59:59Z",
"priceDimensions": {
"U4V6Y3USKUYCB6Q5.6QCMYABX3D.2TG2D8R56U": {
"rateCode": "U4V6Y3USKUYCB6Q5.6QCMYABX3D.2TG2D8R56U",
"description": "Upfront Fee",
"unit": "Quantity",
"pricePerUnit": {
"USD": "34800"
},
"appliesTo": []
},
"U4V6Y3USKUYCB6Q5.6QCMYABX3D.6YS6EN2CT7": {
"rateCode": "U4V6Y3USKUYCB6Q5.6QCMYABX3D.6YS6EN2CT7",
"description": "USD 0.0 per Redshift, dw2.8xlarge reserved instance applied",
"beginRange": "0",
"endRange": "Inf",
"unit": "Hrs",
"pricePerUnit": {
"USD": "0.0000000000"
},
"appliesTo": []
}
},
"termAttributes": {
"LeaseContractLength": "1yr",
"OfferingClass": "standard",
"PurchaseOption": "All Upfront"
}
}
}
}
}
}
我将一条记录分条并尝试使用动态映射进行索引,结果如下
{
"awspricingnew" : {
"mappings" : {
"properties" : {
"disclaimer" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"formatVersion" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"offerCode" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"products" : {
"properties" : {
"KNVR5PFC54PXV76M" : {
"properties" : {
"attributes" : {
"properties" : {
"currentGeneration" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"ecu" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"instanceType" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"io" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"location" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"locationType" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"memory" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"operation" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"servicecode" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"servicename" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"storage" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"usageFamily" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"usagetype" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"vcpu" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
}
}
},
"productFamily" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"sku" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
}
}
}
}
},
"publicationDate" : {
"type" : "date"
},
"terms" : {
"properties" : {
"OnDemand" : {
"properties" : {
"KNVR5PFC54PXV76M" : {
"properties" : {
"KNVR5PFC54PXV76M" : {
"properties" : {
"JRTCKXETXF" : {
"properties" : {
"effectiveDate" : {
"type" : "date"
},
"offerTermCode" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"priceDimensions" : {
"properties" : {
"KNVR5PFC54PXV76M" : {
"properties" : {
"JRTCKXETXF" : {
"properties" : {
"6YS6EN2CT7" : {
"properties" : {
"beginRange" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"description" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"endRange" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"pricePerUnit" : {
"properties" : {
"USD" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
}
}
},
"rateCode" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"unit" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
}
}
}
}
}
}
}
}
},
"sku" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"termAttributes" : {
"type" : "object"
}
}
}
}
}
}
}
}
},
"Reserved" : {
"properties" : {
"U4V6Y3USKUYCB6Q5" : {
"properties" : {
"U4V6Y3USKUYCB6Q5" : {
"properties" : {
"6QCMYABX3D" : {
"properties" : {
"effectiveDate" : {
"type" : "date"
},
"offerTermCode" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"priceDimensions" : {
"properties" : {
"U4V6Y3USKUYCB6Q5" : {
"properties" : {
"6QCMYABX3D" : {
"properties" : {
"2TG2D8R56U" : {
"properties" : {
"description" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"pricePerUnit" : {
"properties" : {
"USD" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
}
}
},
"rateCode" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"unit" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
}
}
},
"6YS6EN2CT7" : {
"properties" : {
"beginRange" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"description" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"endRange" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"pricePerUnit" : {
"properties" : {
"USD" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
}
}
},
"rateCode" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"unit" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
}
}
}
}
}
}
}
}
},
"sku" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"termAttributes" : {
"properties" : {
"LeaseContractLength" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"OfferingClass" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"PurchaseOption" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
}
}
}
}
}
}
}
}
}
}
}
}
},
"version" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
}
}
}
}
}
索引这些文档的一般设计原则是什么?我应该通过logstash进行预处理和展平吗?或者,是否有任何方法可以使用预先创建的映射来记录这些json文件,因为我们不知道在products/terms下创建的键
总体目标是提高每种产品的价格。你想提高每件产品的价格,对吗?是的,没错。我试图将产品和术语对象展平。但是一个术语搜索会产生整个文档。总体要求是索引和构建查询,以从术语对象中提取产品及其相应的价格。@willblake是否可以尝试使用Logstash筛选json文件。你可以利用。Json过滤器插件获取包含Json的现有字段,并将其扩展为实际的数据结构。也许这对你有帮助。你想把每件的价格拿出来,对吗?是的,没错。我试图将产品和术语对象展平。但是一个术语搜索会产生整个文档。总体要求是索引和构建查询,以从术语对象中提取产品及其相应的价格。@willblake是否可以尝试使用Logstash筛选json文件。你可以利用。Json过滤器插件获取包含Json的现有字段,并将其扩展为实际的数据结构。也许对你有帮助。
{
"awspricingnew" : {
"mappings" : {
"properties" : {
"disclaimer" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"formatVersion" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"offerCode" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"products" : {
"properties" : {
"KNVR5PFC54PXV76M" : {
"properties" : {
"attributes" : {
"properties" : {
"currentGeneration" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"ecu" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"instanceType" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"io" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"location" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"locationType" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"memory" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"operation" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"servicecode" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"servicename" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"storage" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"usageFamily" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"usagetype" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"vcpu" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
}
}
},
"productFamily" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"sku" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
}
}
}
}
},
"publicationDate" : {
"type" : "date"
},
"terms" : {
"properties" : {
"OnDemand" : {
"properties" : {
"KNVR5PFC54PXV76M" : {
"properties" : {
"KNVR5PFC54PXV76M" : {
"properties" : {
"JRTCKXETXF" : {
"properties" : {
"effectiveDate" : {
"type" : "date"
},
"offerTermCode" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"priceDimensions" : {
"properties" : {
"KNVR5PFC54PXV76M" : {
"properties" : {
"JRTCKXETXF" : {
"properties" : {
"6YS6EN2CT7" : {
"properties" : {
"beginRange" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"description" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"endRange" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"pricePerUnit" : {
"properties" : {
"USD" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
}
}
},
"rateCode" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"unit" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
}
}
}
}
}
}
}
}
},
"sku" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"termAttributes" : {
"type" : "object"
}
}
}
}
}
}
}
}
},
"Reserved" : {
"properties" : {
"U4V6Y3USKUYCB6Q5" : {
"properties" : {
"U4V6Y3USKUYCB6Q5" : {
"properties" : {
"6QCMYABX3D" : {
"properties" : {
"effectiveDate" : {
"type" : "date"
},
"offerTermCode" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"priceDimensions" : {
"properties" : {
"U4V6Y3USKUYCB6Q5" : {
"properties" : {
"6QCMYABX3D" : {
"properties" : {
"2TG2D8R56U" : {
"properties" : {
"description" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"pricePerUnit" : {
"properties" : {
"USD" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
}
}
},
"rateCode" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"unit" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
}
}
},
"6YS6EN2CT7" : {
"properties" : {
"beginRange" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"description" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"endRange" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"pricePerUnit" : {
"properties" : {
"USD" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
}
}
},
"rateCode" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"unit" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
}
}
}
}
}
}
}
}
},
"sku" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"termAttributes" : {
"properties" : {
"LeaseContractLength" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"OfferingClass" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"PurchaseOption" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
}
}
}
}
}
}
}
}
}
}
}
}
},
"version" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
}
}
}
}
}