首页 > 解决方案 > 如何更新 algolia 指数中的新字段

问题描述

如何在现有的 algolia 索引数组中添加新字段值。我在下图中为 ex 创建了一个新索引我的指数

使用此链接中的此方法https://stackoverflow.com/a/49607796/4232013

     user_details.put("user_username", username);
                            user_details.put("user_email_id", email);
                            user_details.put("user_id", UUID);
     Client client = new Client(ApplicationId, AlgoliaKey);
                                    Index index = client.getIndex("Users");

                                    List<JSONObject> array = new ArrayList<JSONObject>();

                                    array.add(new JSONObject(user_details));


                                    index.addObjectsAsync(new JSONArray(array), null);

但后来如果我想添加一个图像 url 我如何在现有索引中更新这个字段我检查了官方文档https://www.algolia.com/doc/api-reference/api-methods/partial-update-objects/ #examples,但对我来说不清楚,任何人都可以帮助我。谢谢

标签: androidgoogle-cloud-firestorealgolia

解决方案


根据官方文档,您可以 partialUpdateObject

  index.partialUpdateObjectAsync(
    new JSONObject("{\"state\": \"California\"}"),
   "myID",//here provide the object Id 
  null
 );

推荐阅读