From 4bc887fb59935bb648092e0baca9a58383213601 Mon Sep 17 00:00:00 2001 From: Melissa Vagi Date: Tue, 2 Jul 2024 13:37:24 -0600 Subject: [PATCH] Add overlapping fields Signed-off-by: Melissa Vagi --- _im-plugin/index-alias.md | 57 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 56 insertions(+), 1 deletion(-) diff --git a/_im-plugin/index-alias.md b/_im-plugin/index-alias.md index 1816b0e0d2..c6f0d870dd 100644 --- a/_im-plugin/index-alias.md +++ b/_im-plugin/index-alias.md @@ -63,7 +63,7 @@ POST /_alias/ ``` {% include copy-curl.html %} -The `` in the above requests can be an index name, a comma-separated list of index names, or a wildcard expression. Use `_all` to refer to all indexes. +The `` in the preceding requests can be an index name, a comma-separated list of index names, or a wildcard expression. Use `_all` to refer to all indexes. To check if `alias1` refers to `index-1`, run one of the following commands: @@ -272,3 +272,58 @@ DELETE index-1/_alias/alias1 {% include copy-curl.html %} After running the request, `alias1` no longer refers to `index-1` but still refers to `index-2`. + +## Overlapping field names + +When querying an alias that points to multiple indexes with overlapping field names of different data types, OpenSearch attempts to merge the data from these indexes. However, due to the conflicting data types, OpenSearch performs implicit casting or type conversion on the field values to reconcile the differences. + +Here's an example: + +```json +PUT /index1 +{ + "mappings": { + "properties": { + "field1": { + "type": "text" + } + } + } +} + +PUT /index2 +{ + "mappings": { + "properties": { + "field1": { + "type": "long" + } + } + } +} + +POST /_aliases +{ + "actions": [ + { + "add": { + "index": "index1", + "alias": "my_alias" + } + }, + { + "add": { + "index": "index2", + "alias": "my_alias" + } + } + ] +} +``` +{% include copy-curl.html %} + +In this example, the two indexes (`index1` and `index2`) have a field named `field1`, but with different data types (`text` and `long`, respectively). The index alias `my_alias` is then created to point to both indexes. + +When querying this alias, OpenSearch attempts to merge the data from both indexes. If a document in `index1` has a string value for `field1`, and a document in `index2` has a numeric value for the same field, OpenSearch performs implicit casting to reconcile the data types. + +Note that this implicit casting can lead to unexpected results or data loss. For example, if a string value cannot be cast to a numeric type, it may be treated as a missing value or cause an error.