Skip to content

Ingest pipeline order is not specified - randoml causing base64 encoded documents in Elasticsearch #328

Description

@slundell

Steps to reproduce

  1. Install fulltext search with Elasticsearch backend using more than one node
  2. occ fulltextsearch:index
  3. Inspect the contents of the index and note that some document's content is base64-encoded.

Expected behaviour

The _source.content field should be plain text

Actual behaviour

The _source.content field is encoded in base64. Use base64decode on the content string and you will get the original file. This may not happen on all Elasticsearch documents if you have more nodes than one.

Server configuration

Web server: Apache on kubernetes behind an nginx ingress

Database: PostgreSQL on kubernetes using CNPG

Nextcloud version: 31.0.2

Fix

The reason this happens is the setup of the attachment ingest plugin. The ingest pipeline is specified in a way that does not specify the order in which each step of the pipeline should be executed. Hence, sometimes, this happens to be an order in which the attachment is not decoded. In a cluster, this might happen on one or more nodes randomly at setup. The fix is to specify the order as a list. This should probably be fixed in the fulltextsearch addon, but my workaround is to do this manually. I do occ fulltextsearch:reset and then apply the correct pipeline via curl. I also apply my custom index mappings, but that should not be strictly needed, IIRC.

Example of ingest pipeline that works for me.

{
    "description": "attachment",
       "processors": [
            {
                "attachment": {
                    "field": "content",
                    "target_field": "attachment",
                    "indexed_chars": -1,
                    "tag": "base64decode",
                    "ignore_missing": false,
                    "remove_binary": true,
                    "on_failure": [
                        {
                            "set": {
                            "description": "Set decode error",
                            "field": "error.message",
                            "value": "Unable to decode attachment.content",
                            "override": false
                            }
                        }
                    ]
                },
                "rename": {
                    "field": "attachment.content",
                    "target_field": "content",
                    "override": true,
                    "tag": "rename-after-base64decode",
                    "ignore_missing": false,
                    "ignore_failure": false,
                    "on_failure": [
                        {
                            "set": {
                            "description": "Set rename error",
                            "field": "error.message",
                            "value": "Unable to rename attachment.content to content",
                            "override": false
                            }
                        }
                    ]
                }
            }
        ]
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status
    Backlog

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions