解决:elasticsearch 更新报错:The number of object passed must be even but was [1]

Posted 微风--轻许--

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了解决:elasticsearch 更新报错:The number of object passed must be even but was [1]相关的知识,希望对你有一定的参考价值。

前些天发现了一个巨牛的人工智能学习网站,通俗易懂,风趣幽默,忍不住分享一下给大家。点击跳转到教程。

1. 错误的代码写法:

 @Autowired
    private ElasticsearchOperations esOperations; 


public void updateAxxxData(List<AxxxModel> axxxs) 

        for (AxxxModel al : axxxs) 
            UpdateQuery update = new UpdateQuery();
            update.setIndexName("coll_axxxm_sxxxxxxx_es");
            update.setType("coll_axxxm_sxxxxxxx_es");
            UpdateRequest request = new UpdateRequest();      
            request.doc(al);
            update.setUpdateRequest(request);
            esOperations.update(update);
        
    

2. 运行后报错:

  java.lang.IllegalArgumentException: The number of object passed must be even but was [1]

3. 报错行为:  request.doc(al);

4. 把对象改为用Map,循环中代码调整为:

            UpdateQuery update = new UpdateQuery();
            update.setIndexName("coll_axxxm_sxxxxxxx_es");
            update.setType("coll_axxxm_sxxxxxxx_es");
            UpdateRequest request = new UpdateRequest();

            Map<String, Object> alMap = Maps.newHashMap();
            alMap.put("xxx_time", al.getXxx_time());
            alMap.put("xxx_id", al.getXxx_id());
            alMap.put("fxxx_id", al.getFxxx_id());
              
            request.doc(alMap);
            update.setUpdateRequest(request);
            esOperations.update(update);

5. 以上报错即消失。

 

以上是关于解决:elasticsearch 更新报错:The number of object passed must be even but was [1]的主要内容,如果未能解决你的问题,请参考以下文章

解决ES报错NoNodeAvailableException[None of the configured nodes are available:问题

elasticsearch报错:None of the configured nodes are available: []

elasticsearch报错:exceeds the [index.highlight.max_analyzed_offset] limit [1000000]

elasticsearch报错:exceeds the [index.highlight.max_analyzed_offset] limit [1000000]

Elasticsearch使用java读取数据报错NoNodeAvailableException: None of the configured nodes are available: [127.

Elsticsearch 报错with the same id but is a different node instance解决办法