Last active
November 19, 2018 16:37
-
-
Save hackery/261932d8726298156acfc00c395e0f9e to your computer and use it in GitHub Desktop.
Elasticsearch: reindexing to replace null value
This file contains 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
#DELETE jmb-test | |
PUT jmb-test/transactions/1 | |
{ | |
"user" : "jamie" | |
} | |
PUT jmb-test/transactions/2 | |
{ | |
"user" : "kay" | |
} | |
PUT jmb-test/transactions/3 | |
{ | |
} | |
GET jmb-test/_search?q=!_exists_:user | |
# shows document 3 | |
GET jmb-test/_search | |
{ | |
"aggs": { | |
"site": { | |
"terms": { | |
"field": "user.keyword", | |
"size": 10, | |
"missing": "MISSING USER" | |
} | |
} | |
} | |
} | |
# Shows a separate bucket for MISSING USER | |
PUT _template/jmb-test-reindex | |
{ | |
"index_patterns": ["jmb-test-reindex"], | |
"mappings": { | |
"transactions": { | |
"properties": { | |
"user": { | |
"type": "text", | |
"fields": { | |
"keyword": { | |
"type": "keyword", | |
"null_value": "MISSING" | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
POST _reindex | |
{ | |
"source": { | |
"index": "jmb-test" | |
}, | |
"dest": { | |
"index": "jmb-test-reindex" | |
} | |
} | |
GET jmb-test-reindex | |
# Shows the expected mapping in place | |
GET jmb-test-reindex/_search?q=!_exists_:user | |
# still shows doc#3 as having the field missing | |
GET jmb-test-reindex/_search?q=user.keyword:MISSING | |
# 0 docs returned | |
GET jmb-test-reindex/_search | |
{ | |
"aggs": { | |
"user": { | |
"terms": { | |
"field": "user.keyword", | |
"size": 10, | |
"missing": "MISSING USER" | |
} | |
} | |
} | |
} | |
# Shows again a separate bucket for MISSING USER |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment