ES笔记记录

ES笔记记录,第1张

ES笔记记录 1 更新 *** 作

1 更新索引(indexName)下某个字段(cloumnName)的值

POST indexName/_update_by_query
{
  "query": {
    "match_all":{}
  },
  "script": {
    "source": "ctx._source['cloumnName']=1"
  }
}

2 更新索引(indexName)下某个字段(cloumnName)的值

POST my_index/_update_by_query
{
  "script": {
    "lang": "painless",
    "inline": "ctx._source.new_field_name1= '1111'"
  }
}

3 添加字段

# 给索引添加字段
PUT indexName/_mapping/indexTypeName
{
  "properties": {
    "new_field_name1": {
      "type": "keyword"
    },
    "new_field_name2": {
      "type": "keyword"
    },
    "HUMIDITY": {
      "type": "object",
      "enabled": false
    }
  }
}
2 系统配置

参数设置<最大返回记录数>

PUT /index_cat/_settings
{ "index" : { "max_result_window" : 500000}}
3 查询

根据查询条件修改字段:

POST index_cat/_update_by_query
{
  "query": {
    "bool": {
      "must": [
        {
          "match": {
            "iscat":2
          }
        }
      ]
    }
  },
  "script": {
    "source": "ctx._source['iscat']=0"
  }
}

list入参聚合案例 “catid”: [ “001”,“002” ]

GET index_cat/_search
{
  "query": {
    "bool": {
      "must": [
        {
          "bool": {
            "should": [
              {
                "terms": {
                  "catid": [
                    "001","002"
                  ]
                }
              }
            ]
          }
        }
      ]
    }
  },
  "size": 0,
  "aggs": {
    "general_agg_key": {
      "composite": {
        "sources": [
          {
            "catid": {
              "terms": {
                "field": "catid"
              }
            }
          },
          {
            "is_cat": {
              "terms": {
                "field": "is_cat"
              }
            }
          }
        ],
        "size": 1000000
      }
    }
  }
}

查询所有

GET index_cat/_search
{
  "query": {
    "match_all": {}
  }
}

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/5715951.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-17
下一篇 2022-12-18

发表评论

登录后才能评论

评论列表(0条)

保存