curl-rest(elasticsearch)的命令(增删改,修改配置等)【全】

 
file
segment(段,多个document组成)
document(一条记录,一个对象实例)
field(对象的属性)
term(项,分词之后的词条)
 
 
 
# yes
curl -XPUT http://192.168.133.6:9200/bjsxt/
 
curl -XDELETE http://192.168.133.6:9200/bjsxt/
# yes 
curl -XDELETE http://192.168.133.6:9200/test2/
curl -XDELETE http://192.168.133.6:9200/test3/
 
#document:yes 
curl -XPOST http://192.168.198.21:9200/bjsxt/employee -d '
{
 "first_name" : "bin",
 "age" : 33,
 "about" : "I love to go rock climbing",
 "interests": [ "sports", "music" ]
}'
curl -XPOST http://192.168.198.21:9200/bjsxt/employee -d '
{
 "first_name" : "gob bin",
 "age" : 43,
 "about" : "I love to go rock climbing",
 "interests": [ "sports", "music" ]
}'
#add field yes
curl -XPOST http://192.168.198.21:9200/bjsxt/employee/1 -d '
{
 "first_name" : "pablo2",
 "age" : 33,
 "about" : "I love to go rock climbing",
 "interests": [ "sports", "music" ],
 "sex": "man"
}'
----------------------------------------
#put:yes
curl -XPUT http://192.168.198.21:9200/bjsxt/employee/2 -d '
{
 "first_name" : "god bin",
 "last_name" : "bin",
 "age" : 47,
 "about" : "I love to go rock climbing",
 "interests": [ "sports", "music" ]
}'
curl -XPUT http://192.168.133.6:9200/bjsxt/employee -d '
{
 "first_name" : "god bin",
 "last_name" : "bin",
 "age" : 45,
 "about" : "I love to go rock climbing",
 "interests": [ "sports", "music" ]
}'
curl -XPUT http://192.168.133.6:9200/bjsxt/employee/1 -d '
{
 "first_name" : "god bin",
 "last_name" : "pang",
 "age" : 43,
 "about" : "I love to go rock climbing",
 "interests": [ "sports", "music" ]
}'
curl -XPUT http://192.168.133.6:9200/bjsxt/employee/2 -d '
{
 "first_name" : "gob bin",
 "last_name" : "bin",
 "age" : 46,
 "about" : "I love to go rock climbing",
 "interests": [ "sports", "music" ]
}'
curl -XPUT http://192.168.133.6:9200/bjsxt/employee/3 -d '
{
 "first_name" : "abvc",
 "last_name" : "bin",
 "age" : 40,
 "about" : "I love to go rock climbing",
 "interests": [ "sports", "music" ]
}'
#根据document的id来获取数据:(without pretty)
curl -XGET http://192.168.198.21:9200/bjsxt/employee/1?pretty
#根据field来查询数据:
curl -XGET http://192.168.198.21:9200/bjsxt/employee/_search?q=first_name="bin"
#根据field来查询数据:match
curl -XGET http://192.168.198.21:9200/bjsxt/employee/_search?pretty -d '
{
 "query":
  {"match":
   {"first_name":"bin"}
  }
}'
#对多个field发起查询:multi_match
curl -XGET http://192.168.198.21:9200/bjsxt/employee/_search?pretty -d '
{
 "query":
  {"multi_match":
   {
    "query":"bin",
    "fields":["last_name","first_name"],
    "operator":"and"
   }
  }
}'
#多个term对多个field发起查询:bool(boolean) 
# 组合查询,must,must_not,should 
#  must + must : 交集
#  must +must_not :差集
#  should+should  : 并集
curl -XGET http://192.168.198.21:9200/bjsxt/employee/_search?pretty -d '
{
 "query":
  {"bool" :
   {
    "must" : 
     {"match":
      {"first_name":"bin"}
     },
    "must" : 
     {"match":
      {"age":33}
     }
   }
  }
}'
curl -XGET http://192.168.198.21:9200/bjsxt/employee/_search?pretty -d '
{
 "query":
  {"bool" :
   {
    "must" : 
     {"match":
      {"first_name":"bin"}
     },
    "must_not" : 
     {"match":
      {"age":33}
     }
   }
  }
}'
curl -XGET http://192.168.198.21:9200/bjsxt/employee/_search?pretty -d '
{
 "query":
  {"bool" :
   {
    "must_not" : 
     {"match":
      {"first_name":"bin"}
     },
    "must_not" : 
     {"match":
      {"age":33}
     }
   }
  }
}'
##查询first_name=bin的,或者年龄在20岁到33岁之间的
curl -XGET http://192.168.198.21:9200/bjsxt/employee/_search -d '
{
 "query":
  {"bool" :
   {
   "must" :
    {"term" : 
     { "first_name" : "bin" }
    }
   ,
   "must_not" : 
    {"range":
     {"age" : { "from" : 20, "to" : 33 }
    }
   }
   }
  }
}'
#修改配置
curl -XPUT 'http://192.168.198.21:9200/test2/' -d'{"settings":{"number_of_replicas":2}}'
 
curl -XPUT 'http://192.168.198.21:9200/test3/' -d'{"settings":{"number_of_shards":3,"number_of_replicas":3}}'
 
curl -XPUT 'http://192.168.198.21:9200/test4/' -d'{"settings":{"number_of_shards":6,"number_of_replicas":4}}'
 
 
curl -XPOST http://192.168.9.11:9200/bjsxt/person/_mapping -d'
{
    "person": {
        "properties": {
            "content": {
                "type": "string",
                "store": "no",
                "term_vector": "with_positions_offsets",
                "analyzer": "ik_max_word",
                "search_analyzer": "ik_max_word",
                "include_in_all": "true",
                "boost": 8
            }
        }
    }
}'
 
 
 
 
 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值