How to delete all documents that a field have specific length?

for example I have following documents
{
term: "bo"
},
{
term: "book"
}

I want to delete all documents that "term" field length is less than 3

A few approaches I can think of are:

*Highly recommended that you query first and confirm that the results of your query yield the desired hits.

  1. Utilize delete_by_query API in combination with a script query.

  2. Reindex your data such that the field you're interested in becomes a multi-field, using a token_count with appropriate analyzer for your data. Then delete by query using the token_count field directly with no script.

  3. Reindex using an ingest pipeline with drop processor that filters out docs where the field of interest is less than 3 chars long.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.