Last active
August 29, 2015 14:02
-
-
Save up1/72b982193235e1e4079f to your computer and use it in GitHub Desktop.
ElasticSearch with Payload
This file contains 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
type Payload struct { | |
ProvinceID int `json:"province_id"` | |
} | |
type Suggest struct { | |
Input string `json:"input"` | |
Output string `json:"output"` | |
Payload Payload `json:"payload"` | |
} | |
type Address struct { | |
ProvinceID int `json:"province_id"` | |
ProvinceCode string `json:"province_code"` | |
ProvinceName string `json:"province_name"` | |
SuggestName Suggest `json:"province_name_suggest"` | |
} | |
index := 1 | |
for rows.Next() { | |
var province_id int | |
var province_code string | |
var province_name string | |
var suggest_name string | |
rows.Scan(&province_id, &province_code, &province_name, &suggest_name,) | |
core.Index("suggestion", "address", strconv.Itoa(index), nil, | |
Address{province_id, province_code, province_name, | |
Suggest{suggest_name,suggest_name, Payload{province_id}}}) | |
index++ | |
} |
This file contains 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
curl -X PUT localhost:9200/suggestion/address/1 -d ' | |
{ | |
"province_id" : 1, | |
"province_code" : "01", | |
"province_name" : "นครราชสีมา", | |
"province_name_suggest" : { | |
"input" : "นครราชสีมา", | |
"output": "นครราชสีมา", | |
"payload": { "province_id": 1} | |
} | |
}' |
This file contains 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
curl -XPUT http://localhost:9200/suggestion -d '{ | |
"mappings": { | |
"address": { | |
"properties": { | |
"province_id": {"type": "integer"}, | |
"province_code": {"type": "string"}, | |
"province_name": {"type": "string"}, | |
"province_name_suggest" : { | |
"type" : "completion", | |
"payloads" : true | |
} | |
} | |
} | |
} | |
}' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment