如何忽略动态字段进行索引,但需要存储值



在每个文档中,我都有几个动态字段。我想忽略这些字段进行索引,但不需要将完整的值存储在ES中。这里我尝试了对象类型和嵌套类型,但仍然添加了这些字段用于索引。此外,获取异常值时超出了默认字段数。

示例:

{
"graphType": "Node",
"id": "ETA:bb16f173-8152-4e18-ac15-410438ffaf8e",
"type": "StateNode",
"properties": {
"name": "ETA:ETAViolation",
"tenantId": "f9688078-9ff9-46b3-9b0d-d1b4d5f875d7",
"valueHistory": {
"1597952938315": "1"
},
"id": "ETA:bb16f173-8152-4e18-ac15-410438ffaf8e",
"type": "ETA:ETAViolation",
"value": {
"1597952938315": "1"
},
"fromId": "bb16f173-8152-4e18-ac15-410438ffaf8e",
"classType": "StateNode",
"sid": "ETA",
"cid": "ETAViolation"
}
} 

{
"graphType": "Node",
"id": "ETA:8541fb08-8c83-4229-804b-92d57e22e9a2",
"type": "StateNode",
"properties": {
"name": "ETA:ETAViolation",
"tenantId": "f9688078-9ff9-46b3-9b0d-d1b4d5f875d7",
"valueHistory": {
"1597952938447": "3"
},
"id": "ETA:8541fb08-8c83-4229-804b-92d57e22e9a2",
"type": "ETA:ETAViolation",
"value": {
"1597952938447": "3"
},
"fromId": "8541fb08-8c83-4229-804b-92d57e22e9a2",
"classType": "StateNode",
"sid": "ETA",
"cid": "ETAViolation"
}
}

这是两个示例文档,在每个文档中都有两个字段valuevalueHistory。在这些字段中,我得到了许多动态字段,如1597952938315159395293831588。我想忽略这些字段进行索引,但需要将字段存储在ES索引中。

请任何人帮忙。提前感谢。

您的映射应该是这样的,我省略了一些重复的字段。

{
"mappings": {
"post": {
"dynamic": "strict",
"properties": {
"graphType": {
"type": "keyword"
},
"id": {
"type": "keyword"
},
"type": {
"type": "keyword"
},
"name": {
"type": "keyword"
},
"tenantId": {
"type": "keyword"
},
"nested_value": {
"type": "nested",
"properties": {
"key": {
"type": "long",
"store": true
},
"value": {
"type": "integer",
"store": true
}
}
},
"from_id": {
"type": "keyword"
},
"classType": {
"type": "keyword"
},
"sid": {
"type": "keyword"
},
"cid": {
"type": "keyword"
}
}
}
}
}

你需要插入这样的数据:

{
"graphType": "Node",
"id": "ETA:bb16f173-8152-4e18-ac15-410438ffaf8e",
"type": "StateNode",
"name": "ETA:ETAViolation",
"tenantId": "f9688078-9ff9-46b3-9b0d-d1b4d5f875d7",
"nested_value": [
{
"key": 1597952938315,
"value": 1
}
],
"from_id": "bb16f173-8152-4e18-ac15-410438ffaf8e",
"classType": "StateNode",
"sid": "ETA",
"cid": "ETAViolation"
}

可以在嵌套字段中键入和值。而且你也可以很容易地在上面进行搜索。

最新更新