聚合查询参考:https://www.cnblogs.com/duanxz/p/6528161.html
1. 删除
POST http://ip:port/索引/类型/_delete_by_query
条件:删除所有query语句匹配上的
{
"query": {
"match": {
"name": "根据name条件删除"
}
}
}
2. 修改
1. 根据条件更新
POST http://127.0.0.1:9200/索引/类型/id/_update_by_query
{
"script": {
"source": "ctx._source['user_name']='csdn';ctx._source['age']=12;"
},
"query": {
"term": {
"user_id": 60
}
}
}
term:条件的意思
执行上面的query,意思是把,索引/类型下的所有符合user_id为60的记录,把这些的user_name字段全部修改成csdn,把age改成12。
2.修改全部数据
POST http://127.0.0.1:9200/索引/类型/id/_update
{
"doc": {
"user_name": "wh"
}
}
所有记录名称都更改为wh
3. 查询
简单查询
match query 知道分词器的存在,会对field进行分词操作,然后再查询!!!!
term query会去倒排索引中寻找确切的term,它并不知道分词器的存在,这种查询适合keyword、numeric、date等明确值的!!!
terms 查询某个字段里含有多个关键词的文档
wildcard 类似于mysql的like
GET cfg_send_sku/cfg_send_sku/_search
条件查询
{
"query": {
"match": {
"查询字段": "查询条件值"
}
}
}
查看全部
{
"query": {
"match_all": {}
}
}
分页、排序、返回字段过滤查询
{
"query": {
"match_all": {}
},
"from": 0,
"size": 3,
"_source": [
"event_name",
"msgtype",
"recv_time"
],
"sort": {
"recv_time": {
"order": "desc"
}
}
}
from 当前页起始的位置
size 每页条数
_source 列表中放想返回字段
sort 排序
recv_time 排序字段
order 倒序正序
AND、OR、FILTER查询
{
"query": {
"bool": {
"must": [
{
"match": {
"dst_province": "广东"
}
},
{
"match": {
"dst_city": "广州"
}
}
],
"should": [
{
"match": {
"alertlevel": 1
}
}
],
"minimum_should_match" :1,
"filter": {
"range": {
"recv_time": {
"gte": 1621501582000
}
}
}
}
}
}
bool 条件
must 多个条件同时成立,相当于AND
should 相当于OR
filter 过滤
range 范围查询
recv_time 查询字段
minimum_should_match 用于控制bool中should列表,至少匹配几个条件才召回doc
terms
{
"query": {
"terms": {
"title": [ "blog","first"]
}
}
}
term
{
"query": {
"term": {
"title": "blog"
}
}
}
4. 添加
分为指定Id和自动生成Id两种;
1.指定Id使用PUT操作
PUT http://127.0.0.1:9200/索引/类型/id
{
"name": "stono",
"country": "China",
"age": 111,
"date": "1999-11-11"
}
2. 自动生成Id使用POST操作
POST http://127.0.0.1:9200/索引/类型/
{
"name": "stono22",
"country": "China",
"age": 22,
"date": "1999-11-11"
}
5. python操作es
参考:https://blog.csdn.net/sd_bit19/article/details/79739736
6. 官方文档地址
https://www.elastic.co/guide/cn/elasticsearch/guide/current/index.html