Skip to content

Instantly share code, notes, and snippets.

@ebuildy
Created February 18, 2015 09:17
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 ebuildy/1fb1bc7768d4e0d5416a to your computer and use it in GitHub Desktop.
Save ebuildy/1fb1bc7768d4e0d5416a to your computer and use it in GitHub Desktop.
Test ElasticSearch suggest and delete
#!/bin/bash
curl -X DELETE localhost:9200/music
curl -X PUT localhost:9200/music
curl -X PUT localhost:9200/music/song/_mapping -d '{
"song" : {
"properties" : {
"name" : { "type" : "string" },
"suggest" : { "type" : "completion",
"index_analyzer" : "simple",
"search_analyzer" : "simple",
"payloads" : true
}
}
}
}'
curl -X PUT 'localhost:9200/music/song/1' -d '{
"name" : "Nevermind",
"suggest" : {
"input": [ "Nevermind", "Nirvana" ],
"output": "Nirvana - Nevermind",
"payload" : { "id" : 1 },
"weight" : 34
}
}'
curl -X PUT 'localhost:9200/music/song/2' -d '{
"name" : "noel",
"suggest" : {
"input": [ "noel" ],
"output": "noel",
"payload" : { "id" : 2 },
"weight" : 34
}
}'
curl -X PUT 'localhost:9200/music/song/3' -d '{
"name" : "Nirvana cool",
"suggest" : {
"input": [ "Nirvana cool" ],
"output": "Nirvana - cool",
"payload" : { "id" : 3 },
"weight" : 34
}
}'
curl -X PUT 'localhost:9200/music/song/4' -d '{
"name" : "Alice deejay",
"suggest" : {
"input": [ "Alice", "deejay" ],
"output": "Alice deejay",
"payload" : { "id" : 4 },
"weight" : 34
}
}'
curl -X POST localhost:9200/music/_optimize
echo "\n"
curl -X POST 'localhost:9200/music/_suggest?pretty' -d '{
"song-suggest" : {
"text" : "n",
"completion" : {
"field" : "suggest"
}
}
}'
echo "\n"
curl -X DELETE localhost:9200/music/song/2
echo "\n"
curl -X POST localhost:9200/music/_optimize?max_num_segments=1
echo "\n"
curl -X POST 'localhost:9200/music/_suggest?pretty' -d '{
"song-suggest" : {
"text" : "n",
"completion" : {
"field" : "suggest"
}
}
}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment