ElasticSearch - Delete documents by specific field
This seemingly simple task is not well-documented in the ElasticSearch documentation:
We have an ElasticSearch instance with an index that has a field in it called sourceId
. What API call would I make to first, GET
all documents with 100 in the sourceId
field (to verify the results before deletion) and then to DELETE
same documents?
elasticsearch
add a comment |
This seemingly simple task is not well-documented in the ElasticSearch documentation:
We have an ElasticSearch instance with an index that has a field in it called sourceId
. What API call would I make to first, GET
all documents with 100 in the sourceId
field (to verify the results before deletion) and then to DELETE
same documents?
elasticsearch
add a comment |
This seemingly simple task is not well-documented in the ElasticSearch documentation:
We have an ElasticSearch instance with an index that has a field in it called sourceId
. What API call would I make to first, GET
all documents with 100 in the sourceId
field (to verify the results before deletion) and then to DELETE
same documents?
elasticsearch
This seemingly simple task is not well-documented in the ElasticSearch documentation:
We have an ElasticSearch instance with an index that has a field in it called sourceId
. What API call would I make to first, GET
all documents with 100 in the sourceId
field (to verify the results before deletion) and then to DELETE
same documents?
elasticsearch
elasticsearch
asked Nov 12 '18 at 22:01
Stpete111
5751417
5751417
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
You probably need to make two API calls here. First to view the count of documents, second one to perform the deletion.
Query would be the same, however the end points are different. Also I'm assuming the sourceId
would be of type keyword
Query to Verify
POST <your_index_name>/_search
"size": 0,
"query":
"term":
"sourceId": "100"
Execute the above Term Query and take a note at the hits.total
of the response.
Remove the "size":0
in the above query if you want to view the entire documents as response.
Once you have the details, you can go ahead and perform the deletion using the same query as shown in the below query, notice the endpoint though.
Query to Delete
POST <your_index_name>/_delete_by_query
"query":
"term":
"sourceId": "100"
Once you execute the Deletion By Query, notice the deleted
field in the response. It must show you the same number.
I've used term queries however you can also make use of any Match or any complex Bool Query. Just make sure that the query is correct.
Hope it helps!
Hi Kamal, thanks for your answer. Actually sourceId type is long. How does this change your answer?
– Stpete111
Nov 12 '18 at 23:41
1
@Stpete111 Technically it doesn't. Just don't need to make use ofdouble quotes
around100
. Meaning it would be something like"sourceId": 100
– Kamal
Nov 13 '18 at 6:07
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53270744%2felasticsearch-delete-documents-by-specific-field%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
You probably need to make two API calls here. First to view the count of documents, second one to perform the deletion.
Query would be the same, however the end points are different. Also I'm assuming the sourceId
would be of type keyword
Query to Verify
POST <your_index_name>/_search
"size": 0,
"query":
"term":
"sourceId": "100"
Execute the above Term Query and take a note at the hits.total
of the response.
Remove the "size":0
in the above query if you want to view the entire documents as response.
Once you have the details, you can go ahead and perform the deletion using the same query as shown in the below query, notice the endpoint though.
Query to Delete
POST <your_index_name>/_delete_by_query
"query":
"term":
"sourceId": "100"
Once you execute the Deletion By Query, notice the deleted
field in the response. It must show you the same number.
I've used term queries however you can also make use of any Match or any complex Bool Query. Just make sure that the query is correct.
Hope it helps!
Hi Kamal, thanks for your answer. Actually sourceId type is long. How does this change your answer?
– Stpete111
Nov 12 '18 at 23:41
1
@Stpete111 Technically it doesn't. Just don't need to make use ofdouble quotes
around100
. Meaning it would be something like"sourceId": 100
– Kamal
Nov 13 '18 at 6:07
add a comment |
You probably need to make two API calls here. First to view the count of documents, second one to perform the deletion.
Query would be the same, however the end points are different. Also I'm assuming the sourceId
would be of type keyword
Query to Verify
POST <your_index_name>/_search
"size": 0,
"query":
"term":
"sourceId": "100"
Execute the above Term Query and take a note at the hits.total
of the response.
Remove the "size":0
in the above query if you want to view the entire documents as response.
Once you have the details, you can go ahead and perform the deletion using the same query as shown in the below query, notice the endpoint though.
Query to Delete
POST <your_index_name>/_delete_by_query
"query":
"term":
"sourceId": "100"
Once you execute the Deletion By Query, notice the deleted
field in the response. It must show you the same number.
I've used term queries however you can also make use of any Match or any complex Bool Query. Just make sure that the query is correct.
Hope it helps!
Hi Kamal, thanks for your answer. Actually sourceId type is long. How does this change your answer?
– Stpete111
Nov 12 '18 at 23:41
1
@Stpete111 Technically it doesn't. Just don't need to make use ofdouble quotes
around100
. Meaning it would be something like"sourceId": 100
– Kamal
Nov 13 '18 at 6:07
add a comment |
You probably need to make two API calls here. First to view the count of documents, second one to perform the deletion.
Query would be the same, however the end points are different. Also I'm assuming the sourceId
would be of type keyword
Query to Verify
POST <your_index_name>/_search
"size": 0,
"query":
"term":
"sourceId": "100"
Execute the above Term Query and take a note at the hits.total
of the response.
Remove the "size":0
in the above query if you want to view the entire documents as response.
Once you have the details, you can go ahead and perform the deletion using the same query as shown in the below query, notice the endpoint though.
Query to Delete
POST <your_index_name>/_delete_by_query
"query":
"term":
"sourceId": "100"
Once you execute the Deletion By Query, notice the deleted
field in the response. It must show you the same number.
I've used term queries however you can also make use of any Match or any complex Bool Query. Just make sure that the query is correct.
Hope it helps!
You probably need to make two API calls here. First to view the count of documents, second one to perform the deletion.
Query would be the same, however the end points are different. Also I'm assuming the sourceId
would be of type keyword
Query to Verify
POST <your_index_name>/_search
"size": 0,
"query":
"term":
"sourceId": "100"
Execute the above Term Query and take a note at the hits.total
of the response.
Remove the "size":0
in the above query if you want to view the entire documents as response.
Once you have the details, you can go ahead and perform the deletion using the same query as shown in the below query, notice the endpoint though.
Query to Delete
POST <your_index_name>/_delete_by_query
"query":
"term":
"sourceId": "100"
Once you execute the Deletion By Query, notice the deleted
field in the response. It must show you the same number.
I've used term queries however you can also make use of any Match or any complex Bool Query. Just make sure that the query is correct.
Hope it helps!
answered Nov 12 '18 at 22:57
Kamal
1,6361820
1,6361820
Hi Kamal, thanks for your answer. Actually sourceId type is long. How does this change your answer?
– Stpete111
Nov 12 '18 at 23:41
1
@Stpete111 Technically it doesn't. Just don't need to make use ofdouble quotes
around100
. Meaning it would be something like"sourceId": 100
– Kamal
Nov 13 '18 at 6:07
add a comment |
Hi Kamal, thanks for your answer. Actually sourceId type is long. How does this change your answer?
– Stpete111
Nov 12 '18 at 23:41
1
@Stpete111 Technically it doesn't. Just don't need to make use ofdouble quotes
around100
. Meaning it would be something like"sourceId": 100
– Kamal
Nov 13 '18 at 6:07
Hi Kamal, thanks for your answer. Actually sourceId type is long. How does this change your answer?
– Stpete111
Nov 12 '18 at 23:41
Hi Kamal, thanks for your answer. Actually sourceId type is long. How does this change your answer?
– Stpete111
Nov 12 '18 at 23:41
1
1
@Stpete111 Technically it doesn't. Just don't need to make use of
double quotes
around 100
. Meaning it would be something like "sourceId": 100
– Kamal
Nov 13 '18 at 6:07
@Stpete111 Technically it doesn't. Just don't need to make use of
double quotes
around 100
. Meaning it would be something like "sourceId": 100
– Kamal
Nov 13 '18 at 6:07
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53270744%2felasticsearch-delete-documents-by-specific-field%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown