Elasticsearch: delete_by_metadata_field deletes other annotations whose id shares a token, and at most 10 documents
Maintainers usually reply within 1 day
@aniketatgithub is already working on this.
Since Nov 25, 2026.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 35/100
Research direction
Start in api/core/rag/datasource/vdb/elasticsearch/elasticsearch_vector.py at ElasticSearchVector.delete_by_metadata_field, which currently issues a match query and deletes the returned hits without a size; the Huawei Cloud backend has the same method. Read the annotation index mapping to see which metadata.* fields are declared keyword, then compare with the flow through update_annotation_to_index_task and delete_annotation_index_task. Done means the delete uses a term query against the field and its keyword subfield via delete_by_query, covered by a unit test plus the failing Elasticsearch e2e test. Note the reporter states a fix and PR are already in preparation.
Written by the indexing model from the issue text.
Description
Self Checks
- I have read the Contributing Guide and Language Policy.
- This is only for bug report, if you would like to ask a question, please head to Discussions.
- I have searched for existing issues search for existing issues, including closed ones.
- I confirm that I am using English to submit this report, otherwise it will be closed.
- 【中文用户 & Non English User】请使用英语提交,否则会被关闭 :)
- Please do not modify this template :) and fill in all the required fields.
Dify version
main (580416d, api 1.20.0)
Cloud or Self Hosted
Self Hosted (Source)### Steps to reproduce
Against docker.elastic.co/elasticsearch/elasticsearch:8.14.3 (the image in docker-compose), with the annotation documents the annotation tasks index (metadata with doc_id, annotation_id, app_id):
a = "1b9d6bcd-bbfd-4b2d-9b5d-ab8dfbbd4bed"
b = "7c0e2f3a-1111-4b2d-8f00-0123456789ab" # shares only the group "4b2d" with a
vector.create(texts=[annotation(a, app_id), annotation(b, app_id)] + [annotation(uuid4(), app_id) for _ in range(13)], embeddings=...)
vector.delete_by_metadata_field("annotation_id", a) # update/delete of one annotation
vector.delete_by_metadata_field("app_id", app_id) # enable_annotation_reply_task
✔️ Expected Behavior
Deleting by annotation_id removes only that annotation (14 left), and deleting by app_id removes all 15.
❌ Actual Behavior
Deleting annotation a also removes annotation b (13 left), and deleting by app_id removes only 10, leaving 3.
ElasticSearchVector.delete_by_metadata_field searches with {"match": {"metadata.<key>": value}} and deletes the hits. The index mapping only declares metadata.doc_id and metadata.document_id as keyword, so annotation_id and app_id get the dynamic mapping, an analyzed text field. A match query splits the UUID into tokens and matches any document that shares one; UUID4s share their third group (4 hex digits after the version digit, 4096 values) often, so in an app with a few hundred annotations, updating or deleting one annotation (update_annotation_to_index_task, delete_annotation_index_task) can silently remove others from the annotation reply index. The search also has no size, so it returns and deletes at most 10 hits.
The Huawei Cloud backend has the same delete_by_metadata_field.
I have a fix with tests (term queries on the field and its keyword subfield, through delete_by_query; unit test and an Elasticsearch e2e test that fails on main) and will open a PR.
- Dominant language
- Python
- Stars
- 162k
- Forks
- 25.6k
- Avg merge
- 15h 9m
- Merged PRs (30d)
- 606
Getting set up
Starts the project's dev container in your browser, under your own GitHub account.
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from langgenius/dify
-
OpenSearch: text_exists() queries OpenSearch _id instead of metadata.doc_id, so it always returns False for indexed chunksPossibly taken @SanemIzci claimed this 1 day ago. Open🐞 bug
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
langgenius/dify#47109 · 1 comment · 1 reaction ·
Maintainers usually reply within 1 day
-
Log only execution identifiers when a workflow worker starts a runPossibly taken @kinglegendzzh claimed this 1 day ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
langgenius/dify#47094 · 2 reactions ·
Maintainers usually reply within 1 day
-
Node.js SDK declares a response body for 204 conversation deletionPossibly taken @Wang-Zephyr claimed this 5 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
langgenius/dify#46883 · 1 comment · 1 reaction ·
Maintainers usually reply within 1 day
-
Provider IDs with a trailing newline are silently accepted and propagatedPossibly taken @Batianxieshen1 claimed this 5 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
langgenius/dify#46875 · 1 comment · 1 reaction ·
Maintainers usually reply within 1 day
-
Agent Python SDK polling rejects function-tool results that SSE acceptsPossibly taken @EndlessRoad-max claimed this 5 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
langgenius/dify#46868 · 1 reaction ·
Maintainers usually reply within 1 day
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 79/100
micronaut-projects/micronaut-core#14585 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
langgenius/graphon#443 ·
Maintainers usually reply within 2 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
Maintainers usually reply within 1 day
-
[BUG]: Management endpoints /v1/memory/stats and /v1/memory/counts bypass API key authenticationOpen
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
docling-project/docling-serve#788 ·
Maintainers usually reply within 1 day
-
Mend: dependency security vulnerability untriaged
Difficulty 1/5 Under an hour Newbie friendliness 78/100
opensearch-project/cross-cluster-replication#1805 ·
Maintainers usually reply within 1 day