elasticsearch查询字段更新

POST congestion-2021-03/_update_by_query
{
  "query": {
   "range": {
     "state": {
      
       "lte": 2
     }
   }
  },"script" : {
        "source": "ctx._source.state= params.state",
        "lang": "painless",
        "params" : {
            "state" : 4
        }
    }
  
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Elasticsearch可以根据字段进行查询,具体步骤如下: 1. 创建索引 首先需要创建一个包含需要查询字段的索引,例如: ```json PUT my_index { "mappings": { "properties": { "title": { "type": "text" }, "description": { "type": "text" }, "category": { "type": "keyword" }, "price": { "type": "float" }, "rating": { "type": "integer" } } } } ``` 这个索引包含了五个字段:`title`、`description`、`category`、`price`、`rating`。其中`title`和`description`是文本类型,`category`是关键词类型,`price`和`rating`是浮点数和整数类型。 2. 添加数据 可以使用`POST`请求向索引中添加数据,例如: ```json POST my_index/_doc/1 { "title": "Elasticsearch 101", "description": "Learn the basics of Elasticsearch", "category": "Books", "price": 19.99, "rating": 4 } POST my_index/_doc/2 { "title": "Advanced Elasticsearch", "description": "Master the art of Elasticsearch", "category": "Books", "price": 29.99, "rating": 5 } POST my_index/_doc/3 { "title": "Elasticsearch for Developers", "description": "A guide to Elasticsearch for developers", "category": "Books", "price": 24.99, "rating": 4 } ``` 这里添加了三个文档,每个文档包含了五个字段。 3. 查询数据 使用`GET`请求可以根据字段进行查询,例如: ```json GET my_index/_search { "query": { "match": { "title": "elasticsearch" } } } ``` 这个查询会匹配`title`字段中包含`elasticsearch`的文档。 可以使用各种不同的查询类型和过滤器来根据不同的字段进行查询。例如: ```json GET my_index/_search { "query": { "bool": { "must": [ { "match": { "title": "elasticsearch" } }, { "match": { "category": "Books" } } ], "filter": { "range": { "price": { "gte": 20 } } } } } } ``` 这个查询会匹配`title`字段中包含`elasticsearch`、`category`字段等于`Books`、`price`字段大于等于`20`的文档。 总之,Elasticsearch可以非常方便地根据字段进行查询,开发者可以根据需要选择不同的查询类型和过滤器来进行精确查询
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值