I'd like to know if it's possible to use conditions when I define the mapping of an index, because depending on certain values of a field, other fields are then required.
For example :
PUT /my-index
{
"mappings": {
"properties": {
"age": { "type": "integer" },
"email": { "type": "keyword" },
"name": { "type": "text" },
"is_external": {"type": "boolean" }
if [is_external] == true {
"adress": { "type": "text" },
"date": { "type": "date" }
}
}
}
}
If there's no way to do this, how can I deal with it ?
It doesn't make sense to do this kind of checks at the mapping level, because ultimately your index will contain both documents with
is_external: trueandis_external: falseand so the mapping will have to also contain theaddressanddatefield definitions for the documents whereis_external: trueand there can only be one single mapping for each index.If you want to enforce that a document with
is_external: truealso contains theaddressanddatefields, then you can do this using an ingest pipeline with adropprocessor: