dsgdhtr_43654 2018-04-20 14:38 采纳率: 100%
浏览 5

更新整个选定的弹性记录

Using olivere/elastic to connect my Go (1.10) to my Elastic search, which is running in a Docker container.

Now when the database has an update it will run a trigger to my API which should search for that record in my Elastic search, if not found add a new record or if found update the whole record.

Now I have the add new record code in place and its working but I can not see how to update the whole record, selected elements of that record I can but not the whole record.

Here is what I have:

testData := []byte(`{"data1":"22222","data2":"ddddd"}`)

script := elastic.NewScript("ctx._source = params.newCont").Params(map[string]interface{}{"newCont": testData})

put1, _ := client.Update().
                Index("myindex").
                Type("mytype").
                Id("id-here").
                Script(script).
                Do(ctx)

fmt.Println( put1 )

Now when I update _source to something like _source.data1 I can update that but I want my testData var to update all records within this id. The testData var is just for testing, I will be loading this from the database, as I have no idea what would have changed, I need the whole record updated?

Thanks.

  • 写回答

1条回答 默认 最新

  • doumu9799 2018-04-28 12:11
    关注

    Make sure to read the unit tests of github.com/olivere/elastic as well. E.g. update_test.go and update_integration_test.go illustrate how to do updates. Combine that the official documentation and you will become a pro with Elasticsearch very soon :-)

    评论

报告相同问题?

悬赏问题

  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100