I'm currently building a search for an ecommerce system using ElasticSearch (PHP client) but I've run in to an issue
The data I'm storing is a mixture of simple text (e.g. product titles) and lists (e.g. colours, sizes)
The issue I've ran in to is when a product doesn't have any colours
I have the following fields
id - integer
title - string
codes - array
properties - array
attributes - array
So when I send up a product, it looks like this
id: 1
title: ABC
codes: ['ABC', '123']
properties: ['purple']
attributes: ['large', 'small']
This works as expected, but when I try and send something like this
id: 2
title: DEF
codes: ['DEF']
properties: []
attributes: []
It throws an error:
{"error":{"root_cause":[{"type":"mapper_parsing_exception","reason":"object mapping for [codes] tried to parse field [null] as object, but found a concrete value"}],"type":"mapper_parsing_exception","reason":"object mapping for [codes] tried to parse field [null] as o bject, but found a concrete value"},"status":400}
I've tried mapping my fields using this for each field (as found here: https://www.elastic.co/guide/en/elasticsearch/reference/current/dynamic.html)
attributes: {
dynamic: true,
properties: []
}
But that doesn't seem to help, and the docs say you can't specify a type of array
Can anyone point me in the right direction?
array_filterbefore indexing them ElasticSearch doesn't index empty arrays anyway.code,propertiesandattributesall should be string not array. (there is no array type)