RCS
RCS

Reputation: 1432

Can we update/delete document from elastic search db without id

I am new to Elastic Search db. With id property i am able to do update and delete but without id property (I mean another property of document which is unique) it is not working. Please let me know, can we do it or not.

Upvotes: 4

Views: 3860

Answers (3)

RCS
RCS

Reputation: 1432

Here is the query to update

POST /indexName/typeName/_update_by_query
{
  "query": { 
    "match": {
      "name": "abc"
    }
  },
  "script": {
    "inline": "ctx._source.description = 'Updated description'"
  }
}

Here is the query delete

POST /indexName/typeName/_delete_by_query
{
  "query": { 
    "match": {
      "name": "abc"
    }
  }
}

Upvotes: 1

Kaushik
Kaushik

Reputation: 2090

You can use _delete_by_query API.

_delete_by_query gets a snapshot of the index when it starts and deletes what it finds using internal versioning. That means that you’ll get a version conflict if the document changes between the time when the snapshot was taken and when the delete request is processed. When the versions match the document is deleted.

Code snippet.

POST twitter/_delete_by_query
{
  "query": { 
    "match": {
      "message": "some message"
    }
  }
}

Upvotes: 0

rohitanand
rohitanand

Reputation: 728

I think what you are looking for is

  1. Update by Query

https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-update-by-query.html

POST twitter/_update_by_query?conflicts=proceed
{
  "query": { 
    "term": {
      "user": "kimchy"
    }
  }
}
  1. Delete by Query

https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-delete-by-query.html

POST twitter/_delete_by_query
{
  "query": { 
    "match": {
      "message": "some message"
    }
  }
}

Upvotes: 5

Related Questions