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

des4xlb0  于 2021-06-14  发布在  ElasticSearch
关注(0)|答案(1)|浏览(268)

在每个文档中,我都有几个动态字段。我想忽略这些字段进行索引,但neet将完整的值存储在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"
    }
}

这是两个示例文档,每个文档中有两个字段value和valuehistory。在这些字段中,我得到许多动态字段,如1597952938315和159795293831588。我想忽略这些字段进行索引,但需要将这些字段存储在es索引中。
拜托,任何人都可以帮忙。提前谢谢。

3zwjbxry

3zwjbxry1#

你的Map应该是这样的,我省略了一些重复的字段。

{
  "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"
}

您可以在嵌套字段中设置键和值。你也可以很容易地在上面搜索。

相关问题