平时一般都用kibana,一般的搜索都有联想,然后有几个不给联想的但经常用的,记录一下
最爱用的文档:https://elasticsearch-py.readthedocs.io/en/master/api.html#indices
1.分词
POST 索引名/_analyze
{
"analyzer": "standard",
"text": ["要分的词"]
}
2.索引复制
POST /_reindex
{
"source": {
"index": "search_v1"
},
"dest": {
"index": "search_v2"
}
}
3.索引文档条件删除
POST 索引名/_delete_by_query
{
"query":{
"match_all": {}
}
}
连索引都删除
DELETE 索引名
{
"query": {
"match_all": {}
}
}
4.keyword限制
ES5.X版本以后,keyword支持的最大长度为32766个UTF-8字符,text对字符长度没有限制。
设置ignore_above后,超过给定长度后的数据将不被索引,无法通过term精确匹配检索返回结果
5.nested里面嵌套很多的时候,会报错fields太多:
PUT 索引名/_settings
{
"settings": {
"index.mapping.total_fields.limit": 4000
}
}
6.条件批量更新字段
POST index/type/_update_by_query
{
"script": {
"inline": "ctx._source.actionTime='20181008104853';ctx._source.createTime='20181008104853'"
},
"query": {
"range": {
"productID": {
"gte": 0,
"lte": 10000
}
}
}
7.普通更新
POST /index/type/id/_update
{
"doc":{
"name":"tom_change"
}
}
8.filter和must
filter和must的区别是filter不会得分,所以能提高效率
9.查看列表
GET /_cat/indices?format=json
10.动态映射
当同一字段不同内容使用不同的分词器或者需要动态映射的场景:https://www.cnblogs.com/umpjls/p/7319225.html
11.增加字段
PUT index/type/_mapping
{
"properties": {
"email": {
"type": "keyword"
}
}
}
12.设置别名
POST /_aliases
{
"actions": [
{
"add": {
"index": "index_1",
"alias": "index_2"
}
}
]
}
13.distinct
{
"query": {
"match_all": {}
},
"collapse": {
"field": field
},
"_source": [field]
}
14.select count(*) from xx group by xx
{
"aggs": {
"name_aggs": {
"terms": {
"field": "name.keyword",
"size": 10
}
}
},
"query": {
"match_all": {
}
}
}
15.判断两个字段相等
{
"query": {
"script": {
"script": {
"inline": "doc['field1.keyword'].value == doc['field2.keyword'].value",
"lang": "painless"
}
}
}
}
16.不返回某些字段
{
"_source": {
"excludes": ["businessGroupCn"]
},
"query": {
"match_all": {}
}
}
17.bulk批量
https://blog.youkuaiyun.com/keyuquan/article/details/82023549
POST index/documents/_bulk
{"index":{}}
{"word":"good","slot_id":"ANY"}
18.nested inner_hits