Support partial document updates in the index

Open
#4,417 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
18/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Active
Tech stack
elasticsearch, php, wordpress
Domain
backend, search

Research direction

This is design work spanning the Indexable and Elasticsearch classes, the sync queue, and the Documents feature. Start by reading how action_edited_term() decides to skip syncs above the Content Items per Index Cycle limit, and how the existing full-sync path builds and sends documents. Done would mean an agreed API for _bulk update actions, handling of missing documents, and hooks, agreed with maintainers before any code is written.

Written by the indexing model from the issue text.

Description

enhancement
Is your enhancement related to a problem? Please describe.

Every sync sends whole documents. When only one or two fields of an object change, ElasticPress still prepares and sends the entire document. Two places where this is expensive:

  • Documents: every attachment sync reads the file from disk, base64-encodes it, and sends it through the ingest pipeline again, even when only the title or caption changed. Re-syncing a set of attachments resends every file, which can mean hundreds of megabytes for a single change.
  • Changes that affect many objects: when a term is edited, every post with that term is re-synced in full, just to update the terms field. action_edited_term() already skips the sync when there are more posts than "Content Items per Index Cycle", and leaves them for the next full sync, because full documents are too heavy to send in one request.

Being able to send only the changed fields would make these updates much lighter and make other targeted updates practical. Examples are fields that depend on a related object, like a post's parent or its author's display name.

Proposal

Add a partial update API to the Indexable and Elasticsearch classes, built on Elasticsearch's _bulk API with update actions:

{ "update": { "_index": "<index>", "_id": "<id>" } }
{ "doc": { "<field>": <value> } }

Points to consider:

  • Missing documents: an update on a document that isn't in the index fails. That should not create a partial document: either skip it or fall back to a full sync of that object.
  • Ingest pipelines: the update API doesn't run the ingest pipeline. That works for Documents, since the pipeline already removes the raw file data and keeps the extracted text, but it should be documented.
  • Sync queue: today the queue holds object IDs only. Partial updates would need to store which fields to update, or a callback that builds them, and merge with a full sync when one is already queued for the same object.
  • Hooks: add hooks before and after partial updates, like the existing ones for full syncs, so integrations can follow them.
  • Elasticsearch versions: handle versions older than 7.0, which need the document type in the action line. Check that it works on ElasticPress.io.
  • Use it in core: update action_edited_term() and Documents to use it.
Designs

N/A

Describe alternatives you've considered
  • _update_by_query with a script: a single request can update every document matching a query, for example all posts with a given term. It's very efficient, but it needs inline scripts on the cluster, and some proxies or clusters may block it. It could be offered as an option where available.
  • Keep sending full documents but in smaller batches: this doesn't solve the Documents case, where the file itself is the cost.
Code of Conduct
  • I agree to follow this project's Code of Conduct

This was done by Claude under my supervision.

Dominant language
PHP
Stars
1.3k
Forks
323
Avg merge
1d 2h
Merged PRs (30d)
24

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from 10up/ElasticPress

All issues in 10up/ElasticPress

Similar issues

More PHP issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.