Skip to content

Instantly share code, notes, and snippets.

@dmregister
Last active August 29, 2015 13:57
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 dmregister/9467385 to your computer and use it in GitHub Desktop.
Save dmregister/9467385 to your computer and use it in GitHub Desktop.
Elasticsearch completion data and cmd
#bulk cmd
curl -XPOST http://127.0.0.1:9200/_bulk --data-binary @file.json
#json file
{"index":{"_index":"autocompletezipcode","_type":"zipcode","_id":41782}}
{"zip":"99830","city":"Kake","state":"AK","suggest":{"input":["99830"],"output":"Kake, AK"}}
{"index":{"_index":"autocompletezipcode","_type":"zipcode","_id":41783}}
{"zip":"99832","city":"Pelican","state":"AK","suggest":{"input":["99832"],"output":"Pelican, AK"}}
#mapping
'autocompleteZipcode' => array(
'properties' => array(
'city' => array(
'type' => 'string'
),
'state' => array(
'type' => 'string'
),
'zip' => array(
'type' => 'string'
),
'neighborhood' => array(
'type' => 'string'
),
'suggest' => array(
'type' => 'completion',
'index_analyzer' => 'keyword',
'search_analyzer' => 'keyword',
'payloads' => false
)
)
)
#suggest query using PHP library
index' => 'autocompletezipcode',
'body' => array(
"autocomplete" => array(
"text" => "33",
"completion" => array(
"size" => 15,
"field" => "suggest"
),
)
)
#curl CMD
curl -XPOST "http://localhost:9200/autocompletezipcode/_suggest" -d'
{
"autoSuggestion": {
"text": "99830",
"completion": {
"field": "suggest"
}
}
}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment