A computed object field is indexed, but not if the field is marked as nested on ElasticSearch

Created on 16 May 2025, 27 days ago

Problem/Motivation

Note that I am using ElasticSearch 7, which means I need to use version 8.x-7.0-alpha5 of this module, and not the latest version.

In SearchAPI, I have defined a processor which indexes a field of type "object" to ElasticSearch, and the code looks like this:

# my_module/src/Plugin/search_api/processor/MyProcessor.php

/**
* ...
* @SearchApiProcessor(
* id = "periode_exploitation",
* )
* ...
*/
class MyProcessor extends ProcessorPluginBase {

/**
* {@inheritdoc}
*/
public function addFieldValues(ItemInterface $item) {
$fields = $item->getFields(FALSE);
$fields = $this->getFieldsHelper()->filterForPropertyPath($fields, NULL,
'periode_exploitation');
foreach ($fields as $field) {
$field->addValue((object) [
'start_date' => '2022-01-01',
'end_date' => '2022-02-01',
]);
}
}
}

I activate this processor at /fr/admin/config/search/search-api/index/MY_INDEX/processors and make sure the field (of type object) is added to /admin/config/search/search-api/index/MY_INDEX/fields

I then have another processor, which is identical to my processor periode_exploitation, but named periode_exploitation2, and it too is activated and has a corresponding object field.

periode_exploitation does not index on ElasticSearch, but periode_exploitation2 does index.

get my_search/_search
{
"query": {
"match": {
"_id": "entity:node/12345:fr"
}
}
}

Yields:

...
"periode_exploitation2" : [
{
"start_date" : "2022-01-01",
"end_date" : "2022-02-01",
}
}
...

But no field periode_exploitation

I ran the following query on ElasticSearch:

get my_search/_mapping

And this gives me:

...
"periode_exploitation" : {
"type" : "nested",
"properties" : {
"start_date" : {
"type" : "date"
},
"end_date" : {
"type" : "date"
}
}
},
"periode_exploitation2" : {
"properties" : {
"start_date" : {
"type" : "date"
},
"end_date" : {
"type" : "date"
}
}
},
...

It seems that the field periode_exploitation had been defined as "nested" on ElasticSearch, whereas periode_exploitation2 had not been defined at all.

My conclusion, therefore, is that, at least in my tests, a field of type "nested" cannot be updated by Drupal with computed data.

Setting this a support request because (1) I am not using (and cannot use) the latest version of this module because my organization uses ElasticSearch 7x. (2) I don't have a complete list of steps to reproduce this from scratch.

Steps to reproduce

Use a processor to try to update a nested field and non-nested field on ElasticSearch, and note that the nested field is not updated, but the non-nested field is.

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

💬 Support request
Status

Active

Component

Elasticsearch Connector

Created by

🇨🇦Canada alberto56

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @alberto56
  • 🇨🇦Canada alberto56

    Documenting this here in case it may be of use to anyone:

    As a workaround, because it seems impossible in my tests to update the "nested" field periode_exploitation using a search_api plugin, I have updated periode_exploitation2. Then, on the ElasticSearch side, I have created a new pipeline with the following processor:

        ctx.periode_exploitation = ctx.periode_exploitation2
    
Production build 0.71.5 2024