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" }
      }
    }
  }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值