Skip to content

Instantly share code, notes, and snippets.

@drewr
Created September 26, 2014 07:48
Show Gist options
  • Save drewr/282f06114b15bb73bcf9 to your computer and use it in GitHub Desktop.
Save drewr/282f06114b15bb73bcf9 to your computer and use it in GitHub Desktop.
#!/bin/sh
curl -XDELETE localhost:9200/foo >/dev/null
curl -XPUT localhost:9200/foo -d '
{
"mappings": {
"completions": {
"properties": {
"bank": {
"payloads": true,
"type": "completion"
}
}
}
},
"settings": {
"number_of_shards": 1,
"number_of_replicas": 0
}
}
'; echo
curl -XPOST localhost:9200/foo/completions -d '
{
"bank": {
"input": [
"Chase",
"Chase Empire State New York",
"New York"
],
"output": "Chase, Empire State, New York",
"payload": {
"beneficiary_id": 1
},
"weight": 5
}
}
'; echo
curl -XPOST localhost:9200/foo/completions -d '
{
"bank": {
"input": [
"BOA New York",
"Bank of America",
"BOA YYZ New York",
"New York"
],
"output": "Bank of America, Empire State, New York",
"payload": {
"beneficiary_id": 2
},
"weight": 2
}
}
'; echo
curl -XPOST localhost:9200/foo/completions -d '
{
"bank": {
"input": [
"Chase",
"Chase Manhattan Plaza New York",
"Manhattan",
"New York"
],
"output": "Chase, Chase Manhattan Plaza, New York",
"weight": 5,
"payload": {
"beneficiary_id": 3
}
}
}
'; echo
# Must refresh for the docs to be immediately searchable!
curl -XPOST localhost:9200/foo/_refresh; echo
# Run suggestions
curl -XPOST localhost:9200/foo/_suggest -d '
{
"bank suggestions": {
"completion": {
"field": "bank",
"fuzzy": {
"edit_distance": 2
}
},
"text": "chas"
}
}
'
curl -XPOST localhost:9200/foo/_suggest -d '
{
"bank suggestions": {
"completion": {
"field": "bank",
"fuzzy": {
"edit_distance": 2
}
},
"text": "new york"
}
}
'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment