我正在尝试使用 v1.4x 中的完成建议器让 ElasticSearch 为我的自动完成服务索引内容。我正在听从ElasticSearch 的建议- 你完成我并且正在使用 Go Client Olivere/elastic。
我的索引方法看起来有点像这样:
func IndexVehicle(client *elastic.Client, vehicle Vehicle) (bool, error) {
// See if it exists already
fetch, err := client.Get().
Index(vehicleIndex).
Type("vehicle").
Id(vehicle.Id).
Do()
if err != nil || fetch.Found {
return false, err
}
vehicleName := fmt.Sprintf("%s %s (%s) %s", vehicle.Make, vehicle.Model, vehicle.Model_year, vehicle.Primary_fuel)
suggest := elastic.NewSuggestField()
suggest.Input(vehicle.Make, vehicle.Model, vehicle.Primary_fuel, vehicle.Model_year).
Output(vehicleName).
Payload(vehicle)
// Go forth and save
put, err := client.Index().
Index(vehicleIndex).
Type("vehicle").
Id(vehicle.Id).
Debug(true).Pretty(true).
BodyJson(indexBody{Name: vehicleName, Suggest: suggest}).
Do()
if err != nil {
return false, err
}
return put.Created, nil
}
现在奇怪的是,在我的一些测试中,这种方法工作正常,项目将被索引。在擦除和重建索引后的其他测试中,测试将失败:
早期的测试在调试中看起来像这样:
2014/12/15 14:11:37 PUT /vehicle/vehicle/369f96459b340507c4688740da3bfe1a?pretty=true HTTP/1.1
Host: localhost:9200
User-Agent: elastic/1.3.1 (darwin-amd64)
Transfer-Encoding: chunked
Accept: application/json
Content-Type: application/json
Accept-Encoding: gzip
{"name":"American Motors Corporation Eagle 4WD (1986) regular","suggest":{"input":["American Motors Corporation","Eagle 4WD","regular","1986"],"output":"American Motors Corporation Eagle 4WD (1986) regular","payload":{"make":"American Motors Corporation","model_year":"1986","model":"Eagle 4WD","primary_fuel":"regular","vehicle_class":"Special Purpose Vehicle 4WD","transmission":"Automatic 3-spd","displacement":"4.2","drive":"4-Wheel or All-Wheel Drive","city_mpg":"15.0","highway_mpg":"19.0","comb_mpg":"17.0"}}}
2014/12/15 14:11:37 HTTP/1.1 201 Created
Content-Length: 134
Content-Type: application/json; charset=UTF-8
慕工程0101907
红糖糍粑
相关分类