Created
May 10, 2019 15:59
-
-
Save DanielVF/3fe8e3610ed67bd89ab13fc9a46c5ff9 to your computer and use it in GitHub Desktop.
reindex elastic search listings with new mappings in two seconds
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
# If running against any data you care about, check the results of each command for success before running the next command. | |
# Create new index | |
curl -X PUT "localhost:9200/listings_two" -H 'Content-Type: application/json' -d' | |
{ | |
"mappings":{"listing":{"properties":{"price.amount":{"type":"double"},"price.currency.id":{"type":"keyword"},"commission":{"type":"double"},"commissionPerUnit":{"type":"double"},"unitsTotal":{"type":"integer"},"language":{"type":"keyword"},"listingType":{"type":"keyword"},"status":{"type":"keyword"},"marketplacePublisher":{"type":"keyword"},"category":{"type":"keyword","copy_to":"all_text"},"subCategory":{"type":"keyword","copy_to":"all_text"},"description":{"type":"text","copy_to":"all_text"},"title":{"type":"text","copy_to":"all_text"},"all_text":{"type":"text"}}}} | |
} | |
' | |
# copy listings to new index | |
curl -X POST "localhost:9200/_reindex" -H 'Content-Type: application/json' -d' | |
{ | |
"source": { | |
"index": "listings" | |
}, | |
"dest": { | |
"index": "listings_two" | |
} | |
} | |
' | |
# delete old index | |
curl -X DELETE "localhost:9200/listings" | |
# recreate old index | |
curl -X PUT "localhost:9200/listings" -H 'Content-Type: application/json' -d' | |
{ | |
"mappings":{"listing":{"properties":{"price.amount":{"type":"double"},"price.currency.id":{"type":"keyword"},"commission":{"type":"double"},"commissionPerUnit":{"type":"double"},"unitsTotal":{"type":"integer"},"language":{"type":"keyword"},"listingType":{"type":"keyword"},"status":{"type":"keyword"},"marketplacePublisher":{"type":"keyword"},"category":{"type":"keyword","copy_to":"all_text"},"subCategory":{"type":"keyword","copy_to":"all_text"},"description":{"type":"text","copy_to":"all_text"},"title":{"type":"text","copy_to":"all_text"},"all_text":{"type":"text"}}}} | |
} | |
' | |
# copy back in listings | |
curl -X POST "localhost:9200/_reindex" -H 'Content-Type: application/json' -d' | |
{ | |
"source": { | |
"index": "listings_two" | |
}, | |
"dest": { | |
"index": "listings" | |
} | |
} | |
' | |
# delete old index | |
curl -X DELETE "localhost:9200/listings_two" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment