Skip to content

Instantly share code, notes, and snippets.

@Vineeth-Mohan
Created September 1, 2015 18:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Vineeth-Mohan/9cffabff7a985b523e31 to your computer and use it in GitHub Desktop.
Save Vineeth-Mohan/9cffabff7a985b523e31 to your computer and use it in GitHub Desktop.
#!/bin/bash
if [ -z $1 ] ; then
echo "Please enter hostname"
exit
fi
hostname=$1
curl -XDELETE "http://$hostname:9200/news"
echo
curl -X PUT "http://$hostname:9200/news" -d '{
"index": {
"number_of_shards": 1,
"number_of_replicas": 1
},
"analysis":{
"analyzer":{
"flat" : {
"type" : "custom",
"tokenizer" : "keyword",
"filter" : "lowercase"
}
}
}
}'
echo
curl -X PUT "http://$hostname:9200/news/artcile/_mapping" -d '{
"artcile" : {
"properties" : {
"title" : { "type" : "string" , "boost" : 2 },
"content" : { "type" : "string" , "boost" : 10 }
}
}
}'
echo
curl -XPOST "http://$hostname:9200/news/artcile" -d '{
"title" : "elephant are big",
"content" : "animals are big"
}'
echo
curl -XPOST "http://$hostname:9200/news/artcile" -d '{
"title" : "animals are big",
"content" : "elephant are big"
}'
echo
sleep 2
curl -XPOST 'http://localhost:9200/news/_search?pretty' -d '{
"query": {
"match": {
"_all": "elephant"
}
}
}'
@Vineeth-Mohan
Copy link
Author

./createTest.sh localhost

{"acknowledged":true}
{"acknowledged":true}
{"acknowledged":true}
{"_index":"news","_type":"artcile","_id":"AU-KMC_lZVOCDMrQ7UMu","_version":1,"created":true}
{"_index":"news","_type":"artcile","_id":"AU-KMC_zZVOCDMrQ7UMv","_version":1,"created":true}
{
"took" : 4,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"failed" : 0
},
"hits" : {
"total" : 2,
"max_score" : 1.5764985,
"hits" : [ {
"_index" : "news",
"_type" : "artcile",
"_id" : "AU-KMC_zZVOCDMrQ7UMv",
"_score" : 1.5764985,
"_source":{
"title" : "animals are big",
"content" : "elephant are big"
}
}, {
"_index" : "news",
"_type" : "artcile",
"_id" : "AU-KMC_lZVOCDMrQ7UMu",
"_score" : 0.3152997,
"_source":{
"title" : "elephant are big",
"content" : "animals are big"
}
} ]
}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment