Skip to content

Instantly share code, notes, and snippets.

@joshski
Last active July 5, 2016 11:34
Show Gist options
  • Save joshski/9fcedd78746fb56eb0eba6568c15c0b0 to your computer and use it in GitHub Desktop.
Save joshski/9fcedd78746fb56eb0eba6568c15c0b0 to your computer and use it in GitHub Desktop.
Elasticsearch multi-field search with stemming
echo
echo "DELETE INDEX"
echo
curl -w "\r\n" -X DELETE http://localhost:9200/temp-index
echo
echo "CREATE MAPPINGS"
echo
curl -w "\r\n" -X POST http://localhost:9200/temp-index -d '{"mappings":{"asset":{"properties":{"name":{"type":"string","analyzer":"snowball"},"description":{"type":"string","analyzer":"snowball"}}}},"settings":{}}'
echo
echo "ADD DOCUMENTS"
echo
curl -w "\r\n" -X POST "http://localhost:9200/temp-index/asset/" -d '{"name":"happy days", "description":"whatevs"}'
curl -w "\r\n" -X POST "http://localhost:9200/temp-index/asset/" -d '{"name":"noble pursuits", "description":"include happiness"}'
curl -w "\r\n" -X POST "http://localhost:9200/temp-index/asset/" -d '{"name":"brexit", "description":"such sadness"}'
echo
echo "REFRESH INDEX"
echo
curl -w "\r\n" -XPOST 'http://localhost:9200/temp-index/_refresh'
echo
echo "SEARCH DOCUMENTS"
echo
curl -w "\r\n" -X GET 'http://localhost:9200/temp-index/_search' -d '{"query":{"bool":{"should":[{"match":{"name":"happy"}},{"match":{"description":"happy"}}]}}}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment