简体   繁体   中英

remove a jsonObject using updateQuery in elasticSearch JAVA api after filtering

I have quite a few data in my elasticSearch. One of the examples is,

{

    "_index": "some_index",

    "_type": "some_type",

    "_id": "AWDpmuZ9u4O0tj_RL7Zr",

    "_score": 1,

    "_source": {

      "avro_schema": "some_data",

      "md_type": "AA"

    }

I want to remove this object - "avro_schema": "some_data", .

Only if md_type is AA from all the documents.

I want to write a JAVA API which performs this action in elasticSearch.

As of now I have done this..

BoolQueryBuilder query = new BoolQueryBuilder();
  query.should(QueryBuilders.boolQuery().must(QueryBuilders.existsQuery("md_type\":\"AA")));

  UpdateByQueryRequestBuilder ubqrb = UpdateByQueryAction.INSTANCE.newRequestBuilder(client);
  Script script = new Script("ctx._source.remove('avro_schema')");
  BulkByScrollResponse response = ubqrb.script(script)
      .filter(QueryBuilders.termQuery("md_type", "AA"))
      .get();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM