es重建索引

索引的数据类型一旦创建时不可以修改的

//首先插入date格式的数据进入,field的数据进行dynamic mapping处理就成了date类型了
PUT /my_index/my_type/10
{
  "title" : "2017-01-10"
}

//查询
GET /my_index/my_type/_search

//尝试插入文本格式的数据,但是报错
PUT /my_index/my_type/2
{
  "title" : "my first title"
}

//重建一个新的索引
PUT /my_index_new
{
  "mappings": {
    "my_type" : {
      "properties": {
        "title" : {
          "type": "text",
          "index": true,
          "analyzer": "standard"
        }
      },
      "_source": {
        "enabled": true
      },
      "_all": {
        "enabled": true
      }
    }
  }
}

//利用scoll批量查询
GET /my_index/my_type/_search?scroll=1ms
{
  "query": {
    "match_all": {}
  },
  "sort": ["_doc"],
  "size": 1

}

//再利用bulk方式批量插入,这里的写法是错误的,因为_bulk后面是没有大括号的
//POST /_bulk
//{
//  {"index" : {"_index":"my_index_new", "_type":"my_type", "_id":"5"}},
//  {"title" : "2017-01-01"}
//}

//下面的写法是正确的
POST /_bulk
{ "index":  { "_index": "my_index_new", "_type": "my_type", "_id": "2" }}
{ "title":    "2017-01-02" }

//查询心索引中的数据
GET /my_index_new/my_type/_search

//将别名从旧索引上移除添加到新的索引上
POST /_aliases
{
  "actions": [
    {
      "remove": {
        "index": "my_index",
        "alias": "isgood"
      }
    },
    {
      "add": {
        "index": "my_index_new",
        "alias": "isgood"
      }
    }
  ]
}

//测试,使用同样的别名,现在查到的是新索引中的数据
GET /isgood/my_type/_search


























猜你喜欢

转载自blog.csdn.net/zs18052449719/article/details/80723631