Skip to content

Instantly share code, notes, and snippets.

@ivpusic
Created June 8, 2014 19:40
Show Gist options
  • Save ivpusic/b7f542ec729bdf88d78f to your computer and use it in GitHub Desktop.
Save ivpusic/b7f542ec729bdf88d78f to your computer and use it in GitHub Desktop.
elasticsearch init script
#!/usr/bin/env bash
echo 'Removing old indexes'
curl -XDELETE 'http://localhost:9200/categories'
curl -XDELETE 'http://localhost:9200/products'
echo '\n\n'
echo 'Removing old rivers'
curl -XDELETE 'localhost:9200/_river/mongodb'
curl -XDELETE 'localhost:9200/_river/mongodb2'
echo '\n\n'
#############################################################
###################------INDEXES--------#####################
#############################################################
echo 'Creating new indexes'
curl -X PUT localhost:9200/categories
curl -X PUT localhost:9200/products
echo '\n\n'
#############################################################
###################------MAPPINGS------######################
#############################################################
echo 'Creating mappings for autocompletion (categories)'
curl -X PUT localhost:9200/categories/category/_mapping -d '{
"properties" : {
"name" : {
"type" : "string",
"copy_to": "suggest"
},
"suggest" : {
"type" : "completion",
"index_analyzer" : "simple",
"search_analyzer" : "simple",
"payloads" : true
}
}
}'
printf '\n\n'
echo 'Creating mappings for autocompletion (products)'
curl -X PUT localhost:9200/products/product/_mapping -d '{
"properties" : {
"name" : {
"type" : "string",
"copy_to": "suggest"
},
"suggest" : {
"type" : "completion",
"index_analyzer" : "simple",
"search_analyzer" : "simple",
"payloads" : true
}
}
}'
printf '\n\n'
echo 'creating river for categories field'
#############################################################
#####################-----MONGO RIVER-----###################
#############################################################
curl -XPUT "localhost:9200/_river/mongodb/_meta" -d '
{
"type": "mongodb",
"mongodb": {
"servers": [
{
"port": 27017,
"host": "127.0.0.1"
}
],
"collection": "categories",
"db": "bidding"
},
"index": {
"name": "categories",
"type": "category"
}
}'
printf '\n\n'
echo 'creating river for products field'
curl -XPUT "localhost:9200/_river/mongodb2/_meta" -d '
{
"type": "mongodb",
"mongodb": {
"servers": [
{
"port": 27017,
"host": "127.0.0.1"
}
],
"collection": "products",
"db": "bidding"
},
"index": {
"name": "products",
"type": "product"
}
}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment