如何建立ElasticSearch里的mappings?

刚接触elasticsearch,好多东西都不会用,百度了很多,都看不懂,终于摸索出了最简单的通过http建立mappings的方法~

有人在建立mappings报各种错误,首先,如果你的这个索引中已经有数据了,你想修改,最简单的方法,重新建立一个新的索引,成功了以后,再将数据拷贝过来。

数据拷贝工具:https://www.npmjs.com/package/elasticsearch-reindex

1.示例说明,建立一个名为 rdx_index_v2的新索引

马赛克的部分,是你的服务器地址

3.设置mappings格式示范:

{
  "settings": {
    "number_of_shards": 5
  },
  "mappings": {
    "rdx_type": {
      "properties": {
        "zhanghu": {
          "type": "string"
        },
        "zy_mingzi": {
          "type": "string"
        },
        "zy_xingbie": {
          "type": "string",
          "index": "not_analyzed"
        },
        "zy_leixing": {
          "type": "string",
          "index": "not_analyzed"
        },
        "zy_hezuo_zishu": {
          "type": "integer"
        }
      }
    }
  }
}

4.点击提交请求,就成功啦~

ps:有问题,可以留言提问~

 

{

"mappings": {
"info": {
"dynamic": "strict",
"properties": {

"id": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 512
}
}
},
"message": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 512
}
}
}
}
}
}

}
原文地址:https://www.cnblogs.com/crystaltu/p/6774300.html