Skip to content

Instantly share code, notes, and snippets.

@gonvaled
Created January 27, 2012 10:56
Show Gist options
  • Save gonvaled/1688268 to your computer and use it in GitHub Desktop.
Save gonvaled/1688268 to your computer and use it in GitHub Desktop.
Setup an Elastic Search index which will index only one field: "note_text"
server="localhost"
printf "\n\nCreate the index\n"
curl -XPUT "$server:9200/index1"
printf "\n\nCreate the mapping\n"
curl -XPUT "$server:9200/index1/mapping1/_mapping" -d '{
"type1" : {
"dynamic" : false,
"properties" : {
"note_text" : {"type" : "string", "store" : "no"}
}
}
}
'
printf "\n\nConfigure the river\n"
curl -XPUT "$server:9200/_river/river1/_meta" -d '{
"type" : "couchdb",
"couchdb" : {
"host" : "localhost",
"port" : 5984,
"user" : "admin",
"password" : "admin",
"db" : "notes"
},
"index" : {
"index" : "index1",
"type" : "type1",
"dynamic" : false
}
}'
# Wait some time for indexing to work
sleep 30
printf "\n\nAnd now search!\n"
curl -XGET "http://$server:9200/index1/_search?q=note_text:hello&pretty=true"
@gonvaled
Copy link
Author

This is the output that I get:

{
"took" : 14,
"timed_out" : false,
"_shards" : {
"total" : 5,
"successful" : 5,
"failed" : 0
},
"hits" : {
"total" : 1,
"max_score" : 0.30685282,
"hits" : [ {
"_index" : "index1",
"_type" : "type1",
"_id" : "2294ef96-22d6-483d-804c-5c1aaa649ccf",
"_score" : 0.30685282, "_source" : {"_rev":"1-25733895b788da968237673166e8f31a","created_at_date":"2012-01-12T19:37:30.533+0000","note_text":"Hello","liferay_organization_id":10531,"_id":"2294ef96-22d6-483d-804c-5c1aaa649ccf","liferay_user_id":10525,"created_at_time":1326397050533}
} ]
}
}

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