gpt4 book ai didi

json - 使用 json 文件在 elasticsearch 中定义映射

转载 作者:行者123 更新时间:2023-12-01 22:10:17 25 4
gpt4 key购买 nike

我尝试使用 json 文件来定义每个索引的默认映射。这就是我正在尝试做的事情:

/usr/share/elasticsearch/config/default-mapping.json

{
"item": {
"properties": {
"uuid": {"type": "string", "store": "yes", "index": "no"},
"title": {"type": "string", "store": "yes", "boost": 5,
"index": "analyzed", "analyzer": "english"},
"description": {"type": "string", "store": "yes", "boost": 3,
"index": "analyzed", "analyzer": "english"},
}

当我尝试查询我的index_test elasticsearch 索引时,我得到:

curl -XGET 'http://...:9200/index_test/_mapping'
{"index_test":{"mappings":{}}}

我使用了此处找到的文档。

https://www.found.no/foundation/elasticsearch-mapping-introduction/

最佳答案

您可以创建index template使用索引的默认配置(索引设置、映射等)。

  1. 为此,请将 default-mapping.json 文件的内容更改为某些内容像:

    {
    "template_1" : {
    "template" : "*",
    "mappings" : {
    "type" : {
    "properties" : {
    "uuid" : {
    "type" : "string",
    "store" : "yes",
    "index" : "no"
    },
    "title" : {
    "type" : "string",
    "store" : "yes",
    "boost" : 5,
    "index" : "analyzed",
    "analyzer" : "english"
    },
    "description" : {
    "type" : "string",
    "store" : "yes",
    "boost" : 3,
    "index" : "analyzed",
    "analyzer" : "english"
    }
    }
    }
    }
    }
    }
  2. 将 default-mapping.json 文件移至/usr/share/elasticsearch/config/templates 目录
  3. 创建新索引

    POST /newindex
  4. 新创建索引的映射:

    {
    "newindex" : {
    "mappings" : {
    "type" : {
    "properties" : {
    "description" : {
    "type" : "string",
    "boost" : 3,
    "store" : true,
    "analyzer" : "english"
    },
    "title" : {
    "type" : "string",
    "boost" : 5,
    "store" : true,
    "analyzer" : "english"
    },
    "uuid" : {
    "type" : "string",
    "index" : "no",
    "store" : true
    }
    }
    }
    }
    }
    }

希望这对您有帮助。

关于json - 使用 json 文件在 elasticsearch 中定义映射,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30286434/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com