bug_x

导航

 

官方参考文档:

https://www.elastic.co/guide/cn/elasticsearch/guide/current/index-doc.html

 

1、查看 有哪些索引:

 

 curl 'localhost:9200/_cat/indices?v'

 

1.1查看索引结构:

 

GET /索引名/_mapping?pretty

创建索引:
PUT 索引名
比如:
put  admin_index
{
"settings": { "number_of_shards": 6, "number_of_replicas": 1 }, "mappings": { "logs": { "properties": { "esCreateTime": { "type": "long" }, "id": { "type": "long" }, "ip": { "type": "text", "fields": { "keyword": { "type": "keyword", "ignore_above": 256 } } }, "uri": { "type": "text", "fields": { "keyword": { "type": "keyword", "ignore_above": 256 } } }, "userId": { "type": "text", "fields": { "keyword": { "type": "keyword", "ignore_above": 256 } } }, "userName": { "type": "text", "fields": { "keyword": { "type": "keyword", "ignore_above": 256 } } } } } } }

 


2、添加索引:

 

 curl -XPUT 'localhost:9200/customer?pretty'
 curl 'localhost:9200/_cat/indices?v'

3、删除索引

  

 curl -XDELETE 'localhost:9200/customer?pretty'
 curl 'localhost:9200/_cat/indices?v'

4、更新数据

 

   

curl -XPOST 'localhost:9200/_index/_type/_id/_update?pretty' -d '
curl -XPOST 'localhost:9200/customer/external/1/_update?pretty' -d '
{
  "doc": { "name": "Jane Doe", "age": 20 }
}

查看原来的数据

curl -XPOST 'localhost:9200/customer/external/_bulk?pretty' -d '

  {"index":{"_id":"1"}}

  {"name": "John Doe" }

  {"index":{"_id":"2"}}

  {"name": "Jane Doe" }

http://localhost:9200/indexName/typeName/_update_by_query
  { "script": {"source":"ctx._source['user_name']='LsiuLi';ctx._source['assignedto_id']='123';"}, "query": {"term": {"user_id": 60} }


 批量处理:

 下面语句批处理执行更新id为1的数据然后执行删除id为2的数据


  curl -XPOST 'localhost:9200/customer/external/_bulk?pretty' -d '

  {"update":{"_id":"1"}}

  {"doc": { "name": "John Doe becomes Jane Doe" } }

  {"delete":{"_id":"2"}}

  '
参考链接:https://www.cnblogs.com/pilihaotian/p/5830754.html

 

posted on 2019-09-10 17:19  bug_x  阅读(245)  评论(0编辑  收藏  举报