ElasticSearch:http请求的使用方式(增删改查)

ElasticSearch支持restful风格的http请求,可以方便的操作es

创建索引和字段

PUT /my-index
{
  "mappings": {
    "properties": {
      "age":    { "type": "integer" },  
      "email":  { "type": "keyword"  }, 
      "name":   { "type": "text"  }     
    }
  }
}

添加索引字段

PUT /my-index/_mapping
{
  "properties": {
    "employee-id": {
      "type": "keyword",
      "index": false
    }
  }
}

修改索引字段

不能修改

删除索引

DELETE /my-index

查看索引映射

GET /my-index/_mapping

查看具体字段映射

GET /my-index/_mapping/field/employee-id
/${索引名}/_mapping/field/${字段名}

添加文档(数据)

_id自动生成

POST /my-index/_doc
{
     "age":   18,  
     "email":  [email protected], 
     "name":   "小张"    
}

有则修改无则添加

_id=1这条记录存在就修改,不存在就插入。

POST /my-index/_doc/1
{
     "age":   18,  
     "email":  [email protected], 
     "name":   "小张"    
}

删除文档

DELETE /my-index/_doc/1

查看文档(根据_id)

GET /my-index/_doc/1

字词查询

标准分词器汉字是一个字为一个词

GET /my-index/_doc/_search
{
    "query": {
        "term": {
            "name": "张"
        }
    }
}

字词查询

default_field:默认查询字段,query:查询条件(会先进行分词)

GET /my-index/_doc/_search
{
    "query": {
        "query_string" : {
            "query" : "(new york city) OR (big apple)",
            "default_field" : "content"
        }
    }
}

查看分词器效果

标准分词器英文按空格分词,中文按字分词

GET /_analyze
# 标准分词器 [this || is || a || test]
{
  "analyzer" : "standard",
  "text" : "this is a test"
}
# 标准分词器 [这 || 是 || 测 || 试]
{
  "analyzer" : "standard",
  "text" : "这是测试"
}

你可能感兴趣的:(ElasticSearch:http请求的使用方式(增删改查))