GET _search?timeout=10ms { "query": { "match_all": {} } } GET _nodes GET _cat/health?v GET /_cat/indices?v GET /_cat/indices?v&h=health,status,index #索引操作 GET /baizhi GET /baizhi/_search PUT /baizhi DELETE /baizhi # 创建index(baizhi)后,在指定index中添加类型user PUT /baizhi POST /baizhi/user { "user": { "properties": { "id": { "type": "text" }, "name": { "type": "text" }, "age": { "type": "integer" }, "created": { "type": "date", "format": "strict_date_optional_time||epoch_millis" } } } } #或者 # 注意: 字符串常用类型:text类型会分词 keyword类型不会分词 POST /baizhi/student { "mappings": { "student": { "properties": { "title": { "type": "text" }, "name": { "type": "text" }, "age": { "type": "integer" }, "created": { "type": "date", "format": "strict_date_optional_time||epoch_millis" } } } } } GET /baizhi/_mapping/ GET /baizhi/_mapping/student GET /baizhi/_mapping/user PUT /ecommerce/product/1 { "name" : "gaolujie yagao", "desc" : "gaoxiao meibai", "price" : 30, "producer" : "gaolujie producer", "tags": [ "meibai", "fangzhu" ] } PUT /ecommerce/product/2 { "name" : "jiajieshi yagao", "desc" : "youxiao fangzhu", "price" : 25, "producer" : "jiajieshi producer", "tags": [ "fangzhu" ] } PUT /ecommerce/product/3 { "name" : "张朝阳,李玮峰", "desc" : "caoyang weifeng", "price" : 40, "producer" : "company producer", "tags": [ "足球" ] } PUT /ecommerce/product/4 { "name" : "张朝阳,马云,马化腾", "desc" : "gaoxiao mayun", "price" : 30, "producer" : "yagao producer", "tags": [ "企业", "CEO" ] } PUT /ecommerce/product/5 { "name" : "马云,马化腾,yagao", "desc" : "loser yagao", "price" : 25, "producer" : "YAGAO producer", "tags": [ "企业" ] } PUT /ecommerce/product/6 { "name" : "郭富城,周伯通", "desc" : "caoben zhiwu", "price" : 40, "producer" : "contain producer", "tags": [ "搞笑" ] } #全量更新 PUT /ecommerce/product/1 { "name" : "gaolujie yagao", "desc" : "gaoxiao meibai qinxin", "price" : 30, "producer" : "gaolujie producer", "tags": [ "meibai", "fangzhu" , "qinxin"] } #局部更新 POST /ecommerce/product/1/_update { "doc": { "name": "jiaqiangban gaolujie yagao" } } GET /ecommerce/ GET /ecommerce/product/1 GET /ecommerce/product/1?version=3 DELETE /ecommerce/product/1 #删除一个document之后,我们可以从侧面证明,它不是立即物理删除的,因为它的一些版本号等信息还是保留的 #1.query string search #因为search参数都是以http请求的query string来附带的 #搜索全部商品 GET /ecommerce/product/_search #搜索商品名称中包含yagao的商品,而且按照售价降序排序: GET /ecommerce/product/_search?q=name:yagao&sort=price:desc #对比一下: #2.query DSL #搜索全部商品 GET /ecommerce/product/_search { "query": { "match_all": {} } } #查询名称包含yagao的商品,同时按照价格降序排序 GET /ecommerce/product/_search { "query" : { "match" : { "name" : "yagao" } }, "sort": [ { "price": "desc" } ] } #3.分页查询 #总共3条商品,假设每页就显示1条商品,现在显示第2页,所以就查出来第2个商品 GET /ecommerce/product/_search { "query": { "match_all": {} }, "from": 1, "size": 1 } #4.查询指定项 #指定要查询出来商品的名称和价格 GET /ecommerce/product/_search { "query": { "match_all": {} }, "_source": ["name", "price"] } #5.过滤查询 #搜索商品名称包含yagao,而且售价大于25元的商品 GET /ecommerce/product/_search { "query" : { "bool" : { "must" : { "match" : { "name" : "yagao" } }, "filter" : { "range" : { "price" : { "gt" : 25 } } } } } } #6.full-text search(全文检索) GET /ecommerce/product/_search { "query" : { "match" : { "producer" : "yagao producer" } } } #7.phrase search(短语搜索) #跟全文检索相对应,相反,全文检索会将输入的搜索串拆解开来,去倒排索引里面去一一匹配,只要能匹配上任意一个拆解后的单词,就可以作为结果返回phrase search,要求输入的搜索串,必须在指定的字段文本中,完全包含一模一样的,才可以算匹配(不区分大小写), 才能作为结果返回 GET /ecommerce/product/_search { "query" : { "match_phrase" : { "producer" : "yagao producer" } } } #8.多条件查询 #名字中有"yagao",描述上可以有fangzhu也可以没有,价格不能是25元 #must表示一定要满足; #should表示可以满足也可以不满足; #must_not表示不能满足该条件; #"minimum_should_match": 1,表示最小匹配度,可以设置为百分百,详情看源文档Elasticsearch Reference [6.4] » Query DSL » Minimum Should Match,设置了这个值的时候就必须满足should里面的设置了,另外注意这边should里面同一字段设置的多个值(意思是当这个值等于X或者等于Y的时候都成立,务必注意格式) GET /ecommerce/_search { "query": { "bool": { "must": [ { "match": { "name": "yagao" } } ], "should": [ { "match": { "desc": "fangzhu" } }, { "match": { "desc": "caoben" } } ], "must_not": [ { "match": { "price": 25 } } ], "minimum_should_match": 1 } } } #9.批处理操作 GET /baizhi/_search #除了能够索引、更新和删除单个文档外,Elasticsearch还提供了使用_bulk API批量执行上述任何操作的能力。这个功能非常重要,因为它提供了一种非常有效的机制,可以以尽可能少的网络往返尽可能快地执行多个操作 # 批量插入多个document #先分配分配索引再插入 POST /baizhi/student/_bulk {"index":{}} {"name":"ww","title":"王五","age":18,"created":"2018-12-27"} {"index":{}} {"name":"zl","title":"赵六","age":25,"created":"2018-12-27"} # 批量操作(包含修改和删除) POST /baizhi/student/_bulk {"update":{"_id":"AWqXPeQxeOcZARgNd0Pm"} } {"doc":{"title":"王小五2"}} #{"delete":{"_id":"AWqXPeQxeOcZARgNd0Pm"}} #10.高级搜索 # 批量插入测试数据 POST /zpark/user/_bulk {"index":{"_id":1}} {"name":"zs","realname":"张三","age":18,"birthday":"2018-12-27","salary":1000.0,"address":"北京市昌平区沙阳路55号"} {"index":{"_id":2}} {"name":"ls","realname":"李四","age":20,"birthday":"2017-10-20","salary":5000.0,"address":"北京市朝阳区三里屯街道21号"} {"index":{"_id":3}} {"name":"ww","realname":"王五","age":25,"birthday":"2016-03-15","salary":4300.0,"address":"北京市海淀区中关村大街新中关商城2楼511室"} {"index":{"_id":4}} {"name":"zl","realname":"赵六","age":20,"birthday":"2003-04-19","salary":12300.0,"address":"北京市海淀区中关村软件园9号楼211室"} {"index":{"_id":5}} {"name":"tq","realname":"田七","age":35,"birthday":"2001-08-11","salary":1403.0,"address":"北京市海淀区西二旗地铁辉煌国际大厦负一楼"} # 查询所有 # 按年龄倒序排列 GET /zpark/user/_search?q=*&sort=age:desc&pretty GET /zpark/user/_search { "query":{ "match_all":{} }, "sort":{ "age":"desc" } } #11.查询address在海淀区的所有用户,并高亮 # 注意: match查询会分词 如:海淀区 会分词为 海 | 淀 | 区 # 需要高亮的字段列表 GET /zpark/user/_search { "query": { "match": { "address":"海淀区" } }, "highlight": { "fields": { "address": {} } } } #12. # 大于等于 大于用 gt # 小于等于 小于用 lt GET /zpark/user/_search { "query": { "range": { "age": { "gte": 20, "lte": 30 } } } } #13.查询名字已s结尾的用户 #? 匹配一个字符 #* 匹配0~n个字符 GET /zpark/user/_search { "query": { "wildcard": { "name": { "value": "*s" } } } } #14.查询id为1,2,3的用户 GET /zpark/user/_search { "query": { "ids": { "values": [1,2,3] } } }
es bulk 批量操作
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u014017121/article/details/68485163
-
es bulk 批量 更新
-
-
使用bulk命令时,REST API以_bulk结尾,批量操作写在json文件中,官网给出的语法格式:
-
-
action_and_meta_data\n
-
optional_source\n
-
action_and_meta_data\n
-
optional_source\n
-
….
-
action_and_meta_data\n
-
optional_source\n
-
-
命令操作类型占一行 数据另起一行
-
-
如 create 格式 案例
-
{“index”:{“_id”:“17”}} // 需要插入的数据类型 action
-
{“name”:“cddd”,“id”:17} // 带插入的action 对应的数据内容
-
-
批量插入
-
-
方法1
-
-
-
curl -XPOST ‘http://localhost:9200/test/addata_index/_bulk’ -d‘
-
{“index”:{“_id”:”17″}}
-
{“name”:”cddd”,”id”:17}
-
{“index”:{“_id”:”18″}}
-
{“name”:”cddd”,”id”:18}
-
{“index”:{“_id”:”19″}}
-
{“name”:”cddd”,”id”:19}
-
{“index”:{“_id”:”20″}}
-
{“name”:”cddd”,”id”:20}
-
‘
-
-
方法 2 新建文件 tt.json
-
-
tt.json 内容
-
-
{“index”:{“_id”:“27”}}
-
{“name”:“cddd”,“id”:27}
-
{“index”:{“_id”:“28”}}
-
{“name”:“cddd”,“id”:28}
-
{ “delete”:{“_id” : 1 }}
-
(注意这里空行)
-
-
curl -XPOST ‘http://localhost:9200/test/addata_index/_bulk’ –data-binary @tt.json
-
-
注意 点 : 如果自己写的json 文件 不要 在每行后 添加 /n 换行符 直接回车就OK
-
-
bulk 好处就是可以 在一个文件里面执行 create update delete 等操作
-
-
-
删除 操作
-
-
新建 del.json 文件
-
-
文件内容
-
{ “delete”:{“_id” : 26 }}
-
{ “delete”:{“_id” : 25}}
-
// 注意这里是空行 要不然只会删除 编号 位 26 的这行数据
-
-
更新操作
-
-
新建文件 up.json
-
-
{“index”:{“_id”:“21”}}
-
{“name”:“最后一次更新数据”}
-
{“index”:{“_id”:“18”}}
-
{“name”:“美好的年龄”}
-
// 。。。。
-
-
注意点 : 如果 是中文 ,请更改文件编码格式为 UTF-8
GET /_search GET /_cat/indices?v GET /filebeat-2019.05.15/doc/_search { "query": { "match": { "message": "get_token.php" } }, "highlight": { "fields": {"message": {}} } } #创建测试索引 PUT /news DELETE /news # 会将文本做最细粒度的拆分 POST /news/international/_mapping { "properties": { "content":{ "type": "text", "analyzer": "ik_max_word", "search_analyzer": "ik_max_word" } } } #插入测试数据 POST /news/international/_bulk {"index":{"_id":1} } {"content":"美国留给伊拉克的是个烂摊子吗"} {"index":{"_id":2}} {"content":"公安部:各地校车将享最高路权"} {"index":{"_id":3}} {"content":"中韩渔警冲突调查:韩警平均每天扣1艘中国渔船"} {"index":{"_id":4}} {"content":"中国驻洛杉矶领事馆遭亚裔男子枪击 嫌犯已自首"} #根据关键词高亮查询 GET /news/international/_search { "query": { "match": { "content": "中国" } }, "highlight": { "fields": {"content": {}} } } ##IK词典扩展次扩展槽词配置 POST news/_analyze { "field": "content", "analyzer":"ik_max_word", "text": ["中国渔船"] } POST news/_analyze { "field": "content", "text": ["渔警"] } POST /_analyze { "analyzer": "ik_smart", "text": ["抖音视频真的好火啊"] }
转载请注明:SuperIT » Kibana简单操作ES