弹性搜索如何索引嵌套列表

问题描述 投票:0回答:1

如何使用列表创建嵌套数据结构的索引?将有otherUserID列表,我不知道如何使用elasticsearch 6.5索引它们。

UserID -> OtherUserID-> name:"text" , count : "long"

json elasticsearch
1个回答
1
投票

您可以使用nested data type创建此类字段和索引的对象列表。请参阅以下示例并根据您的需要进行修改:

制图:

PUT testindex
{
  "mappings": {
    "_doc": {
      "properties": {
        "nestedField": {
          "type": "nested",
          "properties": {
            "field1": {
              "type": "text",
              "fields": {
                "keywords": {
                  "type": "keyword"
                }
              }
            },
            "field2": {
              "type": "integer"
            }
          }
        }
      }
    }
  }
}

添加文件:

对于列表中的单个项目:

PUT testindex/_doc/1
{
  "nestedField": [
    {
      "field1": "Some text",
      "field2": 10
    }
  ]
}

对于列表中的多个项目:

PUT testindex/_doc/2
{
  "nestedField": [
    {
      "field1": "Some other text",
      "field2": 11
    },
    {
      "field1": "random value",
      "field2": 15
    }
  ]
}
© www.soinside.com 2019 - 2024. All rights reserved.