Skip to content

Instantly share code, notes, and snippets.

@jayzeng
Forked from darklow/es_completion_suggest.sh
Created April 28, 2014 21:26
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 jayzeng/11384541 to your computer and use it in GitHub Desktop.
Save jayzeng/11384541 to your computer and use it in GitHub Desktop.
#!/bin/bash
# ========================================
# Testing completion suggest in ElasticSearch
# ========================================
curl -X DELETE localhost:9200/hotels
curl -X PUT localhost:9200/hotels -d '
{
"mappings": {
"hotel" : {
"properties" : {
"name" : { "type" : "string" },
"city" : { "type" : "string" },
"name_suggest" : {
"type" : "completion",
"payloads" : true
}
}
}
}
}'
curl -X PUT localhost:9200/hotels/hotel/3 -d '
{
"name" : "Courtyard by Marriot Munich City",
"city" : "Munich",
"name_suggest" : {
"input" : [
"Courtyard by Marriot Munich City",
"Marriot Munich City",
"General Munich Hotel"
],
"output": "Hotel Marriot",
"weight": 15,
"payload": { "hotel_id": 3}
}
}'
curl -X POST "http://localhost:9200/hotels/_refresh"
# Some debug info
echo
echo "name_suggest input: { \"Courtyard by Marriot Munich City\", \"Marriot Munich City\", \"General Munich Hotel\" }"
echo
echo "# Found using first letters of first words - M, C or G"
curl -X POST "http://localhost:9200/hotels/_suggest?pretty=true" -d '
{
"hotels": {
"text": "M",
"completion": {
"field": "name_suggest"
}
}
}'
echo
echo "# Can't find using Mu, Mun, Munich, City, General, so on"
curl -X POST "http://localhost:9200/hotels/_suggest?pretty=true" -d '
{
"hotels": {
"text": "Munich",
"completion": {
"field": "name_suggest"
}
}
}'
echo
# Found using first letters of first words - M, C or G
# Can't find using Mu, Mun, Munich, City, General, so on
# anyone know why?
# Thank you
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment