Last active
December 21, 2015 14:09
Testing completion suggest in ElasticSearch
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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