Created
October 22, 2025 10:50
-
-
Save kiennt2/414092d4f38edfd42547f6f92fbe2b82 to your computer and use it in GitHub Desktop.
OpenSearch: Make Field Queryable Without Creating New Index
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ### 1 - Update Mapping | |
| ```shell | |
| # example of text field | |
| PUT /your_index_name/_mapping | |
| { | |
| "properties": { | |
| "your_field_path": { | |
| "type": "text", | |
| "fields": { | |
| "keyword": { | |
| "type": "keyword" | |
| } | |
| } | |
| } | |
| } | |
| } | |
| ``` | |
| Result: New documents with this field are immediately queryable. Old documents won't have it, but that's fine. | |
| ### 2 - Update existing documents | |
| ```shell | |
| POST /your_index_name/_update_by_query?wait_for_completion=false&conflicts=proceed | |
| { | |
| "query": { | |
| "match_all": {} | |
| } | |
| } | |
| ``` | |
| Optional - Use a script to populate default values: | |
| ```shell | |
| POST /your_index_name/_update_by_query | |
| { | |
| "query": { | |
| "match_all": {} | |
| }, | |
| "script": { | |
| "source": "if (ctx._source.my_field == null) { ctx._source.my_field = 'default_value' }" | |
| } | |
| } | |
| ``` | |
| ### 3 - Refresh | |
| ```shell | |
| POST /your_index_name/_refresh | |
| ``` | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.