ES常用命令
[TOC]
1. 根据条件删除( _search 改成 _delete_by_query)
{
"query": {
"bool": {
"must": [
{
"terms": {
"general.uuid": [
"cc5a0bcd-7dd5-471a-8ff4-560b88c2ee8e"
]
}
}
]
}
}
}
2. 查询字段是存在,字段中不存在某值
{
"query": {
"bool": {
"must_not": [
{
"term": {
"structVersion.keyword": "2"
}
}
],
"filter": [
{
"exists": {
"field": "manualAnchorPoint"
}
}
]
}
},
"from": 0,
"size": 40
}
3. Http api 请求(Id查询)
curl -XPOST -H 'Content-type':'application/json' 'http://127.0.0.1:9200/edu_epditembank_test/_search?pretty' -d '{"query":{"bool":{"must":[{"terms":{"general.uuid":["ca7868fb-bdb8-458c-acc4-15382c8dd7f5"]}}]}}}' > index.json
4. 解决es查询超过1w条时异常
4.1 Http请求设置
curl -XPUT http://127.0.0.1:9200/_settings -d '{ "index" : { "max_result_window" : 100000000}}
4.2 配置文件设置
修改集群配置config/elasticsearch.yml文件,增加如下配置:
max_result_window: 100000
5. 查询排序
{
"query": {
"bool": {
"must": [
{
"range": {
"mongoid.keyword": {
"gt": "53c8a77c8090404ffcae0a10"
}
}
}
]
}
},
"from": 0,
"size": 10,
"sort": [
{
"mongoid": {
"order": "asc"
}
}
],
"aggs": {}
}
6. 分片延时同步
PUT /_all/_settings{ "settings": { "index.unassigned.node_left.delayed_timeout": "30m"}}
7. 查询es segment 配置
http://127.0.0.1:9200/_cat/segments/edu_epditembank_question_2?v&h=shard,segment,size,size.memory
8. 新增字段mapping
8.1 head添加
put http://127.0.0.1:9200/edu_epditembank_paper/_mapping/type-resource/
{
"properties": {
"supplementaryCatalog": {
"type": "keyword"
}
}
}
8.2 http请求添加
curl -XPUT -H 'Content-type':'application/json' 'http://172.31.12.19:9200/edu_epditembank_paper/_mapping/type-resource/' -d '{"properties":{"supplementaryCatalog":{"type":"keyword"}}}'
9. 副本集设置
curl -XPUT http://127.0.0.1:9200/edu_epditembank_paper/_settings -d '{ "index.number_of_replicas" :"1"}'
10. head启动命令
/data/third_party/elasticsearch-head-master/node_modules/grunt/bin
nohup ./grunt server &
11. 字段长度查询
{"query":{"bool":{"filter":{"script":{"script":"doc['properties.phase.keyword'].values.length > 1"}}}},"from":1,"size":10}
11. 字段返回限制
{"query":{"bool":{"must":[{"range":{"anchorPoint.machine.confidence":{"gt":"0"}}}]}},"_source":{"includes":["general.uuid"],"excludes":[]}}