ElasticSearch操作命令大全

创建索引和映射

1、手动创建索引

curl -XPUT ‘localhost:9200/new-index’

2、获取映射

curl ‘localhost:9200/get-together/_mapping/group?pretty’

定义新映射

curl -XPUT ‘localhost:9200/get-together/_mappering/new-events’ -d ‘{
“new-event”:{
“propeties”:{
“host”:{
“type”: “string”
}}}}’

3、搜索获取数据
ES默认使用了_all字段,索引了所有字段内容

curl ‘localhost:9200/get-together/group/_search?
q=elasticsearch
&field=name,location
&size=1
&pretty’

4、在一个索引,多个类型中搜索(新版本已经废弃type)

curl “localhost:9200/get-together/group,event/_search?q=elasticsearch&pretty”

5、在多个索引中搜索

curl “localhost:9200/get-together,other-index/_search?q=elasticsearch&pretty”

6、在所有索引的某个type下搜索,可以使用_all作为索引的占位符

curl “localhost:9200/_all/type/_search”

7、指定查询的超时时间(默认永不超时)

curl “localhost:9200/get-together/group/_search?q=elasticsearch&pretty&timeout=3s”

8、运行一个类型为query_string的查询

curl ‘localhost:9200/get-together/group/_search?pretty’ -d ‘{
“query”:{
“query_string”:{
“query”: “elasticsearch san francisco”,
“default_field”: “name”,
“default_operatior”:“AND”
}}
}’

9、term查询,如果只在name字段中查找’elastic search’一个词,term查询可能会更快

curl ‘localhost:9200/get-together/group/_search?pretty’ -d ‘{
“query”:{
“term”:{
“name”: “elasticsearch”
}}
}’

10、使用过滤器,如果对搜索的评分不感兴趣,可以使用过滤器查询,过滤器只关心结果是否匹配,并且可以缓存,所以相对更快

curl ‘localhost:9200/get-together/group/_search?pretty’ -d ‘{
“query”:{
“filted”:{
“filter”:{
“term”:{
“name”:“elasticsearch”
}}
}}’

11、聚集查询

curl localhost:9200/get-together/group/_search?pretty -d ‘{
“aggregation”:{
“organizers”:{
“term”:{
“field”:“organizer”}
}
}}’

12、通过ID获取文档

curl ‘localhost:9200/get-together/group/1?pretty’

  • 1
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值