elasticsearch创建index和type操作日志记录

为了学习 elasticsearch,跟着官方文档及网上例子操作了一些,整理记录下来,以供大家参考。
本文所用测试工具:火狐插件HttpRequester。
elasticsearch:2.3

----------------------------------------创建index---------------------------------------------

POST  http://192.168.10.139:9200/megacorp1/
Content-Type: application/json

 -- response --
200 OK
Content-Type:  application/json; charset=UTF-8
Content-Length:  21

{"acknowledged":true}

----------------------------------------查询index---------------------------------------------

GET  http://192.168.10.139:9200/megacorp1/?pretty

 -- response --
200 OK
Content-Type:  application/json; charset=UTF-8
Content-Length:  361

{
  "megacorp1" : {
    "aliases" : { },
    "mappings" : { },
    "settings" : {
      "index" : {
        "creation_date" : "1467844960627",
        "number_of_shards" : "5",
        "number_of_replicas" : "1",
        "uuid" : "3luuvHNGSf2RBYJHxRGUNg",
        "version" : {
          "created" : "2030399"
        }
      }
    },
    "warmers" : { }
  }
}

----------------------------------------创建type---------------------------------------------
POST  http://192.168.10.139:9200/megacorp1/_mapping/type1
Content-Type: application/json
{
  "properties": {
    "text": {
      "type": "string",
      "analyzer": "standard",
      "search_analyzer": "whitespace"
    }
  }
}
 -- response --
200 OK
Content-Type:  application/json; charset=UTF-8
Content-Length:  21

{"acknowledged":true}

----------------------------------------查询type---------------------------------------------
GET  http://192.168.10.139:9200/megacorp1/_mapping/type1?pretty

 -- response --
200 OK
Content-Type:  application/json; charset=UTF-8
Content-Length:  258

{
  "megacorp1" : {
    "mappings" : {
      "type1" : {
        "properties" : {
          "text" : {
            "type" : "string",
            "analyzer" : "standard",
            "search_analyzer" : "whitespace"
          }
        }
      }
    }
  }
}

----------------------------------------修改type
只能添加字段,不能修改和删除字段
POST   http://192.168.10.139:9200/megacorp1/_mapping/type1?pretty
Content-Type: application/json
{
  "properties": {
    "text": {
      "type": "string",
      "analyzer": "standard",
      "search_analyzer": "whitespace"
    },"text1": {
      "type": "string",
      "analyzer": "standard",
      "search_analyzer": "whitespace"
    }
  }
}
 -- response --
200 OK
Content-Type:  application/json; charset=UTF-8
Content-Length:  28

{
  "acknowledged" : true
}


----------------------------------------查询type---------------------------------------------
GET   http://192.168.10.139:9200/megacorp1/_mapping/type1?pretty

 -- response --
200 OK
Content-Type:  application/json; charset=UTF-8
Content-Length:  406

{
  "megacorp1" : {
    "mappings" : {
      "type1" : {
        "properties" : {
          "text" : {
            "type" : "string",
            "analyzer" : "standard",
            "search_analyzer" : "whitespace"
          },
          "text1" : {
            "type" : "string",
            "analyzer" : "standard",
            "search_analyzer" : "whitespace"
          }
        }
      }
    }
  }
}

----------------------------------------删除type---------------------------------------------
esasticSearch2.0中,mapping不再支持删除,

参考: http://elasticsearch.cn/question/234

你可能感兴趣的:(elasticsearch,搜索引擎,api,索引,REST,全文检索)