`
yuan29346
  • 浏览: 14358 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

Elasticsearch常用操作

    博客分类:
  • java
阅读更多

创建索引

curl -XPUT http://localhost:9200/index

检查服务健康状态

curl -X GET "localhost:9200/_cat/health?v"

获得集群中的节点列表

curl -X GET "localhost:9200/_cat/nodes?v"

创建一个索引

curl -X PUT "localhost:9200/customer?pretty"

参数?pretty告诉系统响应json格式数据

查看索引列表

curl -X GET "localhost:9200/_cat/indices?v"

健康状态为黄色,是因为没有副本NODE,一旦配置了副本node,健康状态将变为绿色

 

保存一个数据

curl -X PUT "localhost:9200/customer/_doc/1?pretty" -H 'Content-Type: application/json' -d'

{

  "name": "John Doe"

}

'

查询一个数据

curl -X GET "localhost:9200/customer/fulltext/1?pretty"

删除一个索引

curl -X DELETE "localhost:9200/customer?pretty"

curl -X GET "localhost:9200/_cat/indices?v"

curl -X GET "localhost:9200/customer/1?pretty"

修改数据

curl -X POST "localhost:9200/customer/_doc/1/_update?pretty" -H 'Content-Type: application/json' -d'

{

  "doc": { "name": "Jane Doe", "age": 20 }

}'

修改数据,并进行运算

curl -X POST "localhost:9200/customer/_doc/1/_update?pretty" -H 'Content-Type: application/json' -d'

{

  "script" : "ctx._source.age += 5"

}'

 

 

批量新增数据,覆盖原来的数据

curl -X POST "localhost:9200/customer/_doc/_bulk?pretty" -H 'Content-Type: application/json' -d'

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

{"name": "John Doe111" }

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

{"name": "Jane Doe222" }

'

批量执行,更新,删除动作

curl -X POST "localhost:9200/customer/_doc/_bulk?pretty" -H 'Content-Type: application/json' -d'

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

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

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

'

加载json文件accounts.json中的数据集合

curl -H "Content-Type: application/json" -XPOST "localhost:9200/bank/_doc/_bulk?pretty&refresh" --data-binary "@accounts.json"

URL参数形式查询所有银行数据,按照account_number正排序

curl -X GET "localhost:9200/bank/_search?q=*&sort=account_number:asc&pretty"

 

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics