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":  1234567@123.com, 
     "name":   "小张"    
}

有则修改无则添加

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

POST /my-index/_doc/1
{
     "age":   18,  
     "email":  1234567@123.com, 
     "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" : "这是测试"
}
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容