GET _all
#将文本做最细粒度的拆分
POST _analyze
{
"analyzer": "standard",
"text": "中华人民共和国"
}
#unicode支持,中文分词器良好
POST _analyze
{
"analyzer": "icu_analyzer",
"text": "中华人民共和国"
}
PUT /es_db
GET /es_db
GET /es_db/_settings
HEAD /es_db
#修改索引配置
PUT /es_db/_settings
{
"index":{
"number_of_replicas" : "1"
}
}
PUT /es_db/_doc/1
{
"name":"张三",
"sex":1,
"age":25,
"address":"广州天河公园",
"remark":"java developer"
}
PUT /es_db/_doc/2
{
"name":"李四",
"sex":1,
"age":25,
"address":"广州天河公园",
"remark":"java developer"
}
#自动生成id
POST /es_db/_doc
{
"name":"李四",
"sex":1,
"age":25,
"address":"广州天河公园",
"remark":"java developer"
}
#查询前10条文档
GET /es_db/_doc/_search
#精确查找
GET /es_db/_search
{
"query": {
"term": {
"address": {
"value": "广州天河公园"
}
}
}
}
GET /es_db/_search
{
"query": {
"match": {
"address": "天河公园"
}
}
}
#官方不建议使用uri方式
GET /es_db/_doc/_search?q=age:30
#分页
GET /es_db/_doc/_search?q=age[25 TO 26]&from=0&size=2
GET /es_db/_doc/_search?q=age:>28
GET /es_db/_doc/_search?sort=sex:desc&q=age[28 TO 30]&_source=name,age
#查询文档
GET /es_db/_doc/OH3X-oYBH-hBNh37iVi4
#局部修改文档
POST /es_db/_update/OH3X-oYBH-hBNh37iVi4
{
"doc":{
"age": 28
}
}
#使用update_by_query 更新值
POST /es_db/_update_by_query
{
"query": {
"match": {
"_id": "2"
}
},
"script": {
"source": "ctx._source.age = 30"
}
}
#删除文档
DELETE /es_db/_doc/OH3X-oYBH-hBNh37iVi4
#批量写入bulk,actionName:create,delete,update,index
POST _bulk
{"create":{"_index":"article","_type":"_doc","_id":3}}
{"id":3,"title":"文章标题测试","content":"测试内容66666","tags":["java","面向对象"],"create_time":12312312312}
{"create":{"_index":"article","_type":"_doc","_id":4}}
{"id":4,"title":"文章标题测试4","content":"测试内容66666","tags":["java","面向对象4"],"create_time":12312312312}
GET /article/_search
#删除以前的文档,生成新的文档
POST _bulk
{"index":{"_index":"article","_type":"_doc","_id":3}}
{"id":3,"title":"文章标题测试","content":"测试内容66666","tags":["java","面向对象"],"create_time":12312312312}
{"index":{"_index":"article","_type":"_doc","_id":4}}
{"id":4,"title":"文章标题测试4","content":"测试内容66666","tags":["java","面向对象4"],"create_time":12312312312}
#批量删除
POST _bulk
{"delete":{"_index":"article","_type":"_doc","_id":3}}
{"delete":{"_index":"article","_type":"_doc","_id":4}}
#批量修改
POST _bulk
{"update":{"_index":"article","_type":"_doc","_id":3}}
{"doc":{"title":"ES文章标题测试"}}
{"update":{"_index":"article","_type":"_doc","_id":4}}
{"doc":{"title":"ES文章标题测试4"}}
#批量查询,获取不同index的type数据
GET _mget
{
"docs":[
{
"_index":"es_db",
"_id":1
},
{
"_index":"article",
"_id":3
}
]
}
GET /es_db/_msearch
{}
{"query":{"match_all":{}},"from":0,"size":2}
{"index":"article"}
{"query":{"match":{"title":"ES"}}}
#多字段查询
GET /es_db/_search
{
"query":{
"multi_match": {
"query": "广州张三",
"fields": [
"address",
"name"
]
}
}
}