es查询修改
1.正则查询
GET ip:端口号/process_node/_search { "from" : 0, "size" : 100, "query": { "bool": { "must": [ { "term":{ "robotId" : { "value" : 1234 } } }, { "term":{ "type" : { "value" : "START" } } }, { "regexp": { "config": { "value": ".*TOPIC.*" } } } ] } } }
//通配符查询,相当于like { "from" : 0, "size" : 100, "query": { "bool": { "must": [ { "term":{ "type" : { "value" : "START" } } }, { "wildcard": { "expandNodeConfig": { "value":"*"aaa"*" } } } ] } } }
2. 只查询某个字段,去重排序
ip:端口号/process_node/_search
{
"_source": ["robotId"],
"from" : 0,
"size" : 400,
"query": {
"bool": {
"must": [
{
"regexp": {
"expandNodeConfig": {
"value": ".*系统_.*"
}
}
}
]
}
},
"collapse":{
"field":"robotId"
},
"sort": { "robotId": { "order": "asc" }}
}
3. 修改字段的值
post ip:端口号/process_node/_update_by_query
{
"query": {
"match": {
"_id": "123456"
}
},
"script": {
"source": "ctx._source['expandNodeConfig'] = params['new_expandNodeConfig']",
"params": {
"new_expandNodeConfig":"你好"
}
}
}
4. 分组查询
{
"aggs": {
"ageGroup": {
"terms": {
"field": "age",
"order": {
"_count": "desc"
}
}
}
},
"size": 0
}
5. 查询所有的索引:
a、查询所有index与index相关信息
GET _cat/indices
b、只查询index名称
GET _cat/indices?h=idx
6. 删除和新建索引
1. 先删除原索引
DELETE /my_index
2.新建索引
PUT /my_index
{
{
"mappings": {
"properties": {
"addTime": {
"type": "date"
},
"answerIds": {
"type": "keyword"
},
"categoryId": {
"type": "long"
},
"effectiveEndTime": {
"type": "date"
},
"effectiveStartTime": {
"type": "date"
},
"effectiveType": {
"type": "integer"
},
"enable": {
"type": "boolean"
},
"hits": {
"type": "long"
},
"id": {
"type": "keyword"
},
"modifyTime": {
"type": "date"
},
"parentId": {
"type": "long"
},
"question": {
"type": "text",
"analyzer": "ik_max_word"
},
"relateQuestionIds": {
"type": "keyword"
},
"robotId": {
"type": "long"
},
"similarQuestionIds": {
"type": "keyword"
},
"sourceType": {
"type": "long"
},
"termQuestion": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"userId": {
"type": "long"
}
}
}
}
}
7. 新增字段并设置默认值
//先新增字段,设置字段类型
PUT /{index}/_mapping
{
"properties": {
"new_field": {
"type": "keyword"
}
}
}
//更新字段的值
POST /{index}/_update_by_query
{
"script": {
"inline": "ctx._source.new_field = 'value'"
},
"query": {
"bool": {
"must_not": {
"exists": { "field": "date_field" }
}
}
}
}