org.elasticsearch.action.ActionRequestValidationException: Validation Failed: 1: index is missing;2:

https://blog.csdn.net/mnmiaoyi/article/details/98885628

报错信息

org.elasticsearch.action.ActionRequestValidationException: Validation Failed: 1: index is missing;2: type is missing;
at org.elasticsearch.action.ValidateActions.addValidationError(ValidateActions.java:26)
at org.elasticsearch.action.support.replication.ReplicationRequest.validate(ReplicationRequest.java:176)
at org.elasticsearch.action.index.IndexRequest.validate(IndexRequest.java:148)
at org.elasticsearch.action.TransportActionNodeProxy.execute(TransportActionNodeProxy.java:46)
at org.elasticsearch.client.transport.TransportProxyClient.lambda$execute$0(TransportProxyClient.java:60)
at org.elasticsearch.client.transport.TransportClientNodesService.execute(TransportClientNodesService.java:250)
at org.elasticsearch.client.transport.TransportProxyClient.execute(TransportProxyClient.java:60)
at org.elasticsearch.client.transport.TransportClient.doExecute(TransportClient.java:371)
at org.elasticsearch.client.support.AbstractClient.execute(AbstractClient.java:405)
at org.elasticsearch.client.support.AbstractClient.execute(AbstractClient.java:394)
at org.elasticsearch.action.ActionRequestBuilder.execute(ActionRequestBuilder.java:46)
at org.elasticsearch.action.ActionRequestBuilder.get(ActionRequestBuilder.java:53)
at com.baizhi.TestElaticSearch.testIndex(TestElaticSearch.java:49)

测试的代码

package com.baizhi;
import jdk.nashorn.internal.runtime.logging.Logger;
import org.elasticsearch.action.index.IndexResponse;
import org.elasticsearch.client.transport.TransportClient;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.transport.TransportAddress;
import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.transport.client.PreBuiltTransportClient;
import org.junit.Before;
import org.junit.Test;
import java.io.IOException;
import java.net.InetAddress;
import java.net.UnknownHostException;
public class TestElaticSearch {
    TransportClient transportClient;
    @Before
    public void function() throws UnknownHostException {
       this.transportClient = new PreBuiltTransportClient(Settings.EMPTY)
               .addTransportAddress(new TransportAddress(InetAddress.getByName("192.168.118.100"), 9300));
    }
    @Test
    public void testConn() {
        System.out.println(transportClient);
    }
    /*
    *
    * 创建索引
    *
    *
    * */
    @Test
    public void testIndex() throws IOException {
        XContentFactory.jsonBuilder()
                .startObject()
                .field("name","miaoyi")
                .field("age",19)
                .field("bir","2018-11-18")
                .field("email","miaoyi@26.com")
                .field("content","miaoyi is a good boy !")
                .endObject();
        IndexResponse indexResponse = transportClient.prepareIndex().setSource().get();
        System.out.println(indexResponse.status());
    }
}

问题解决
IndexResponse indexResponse=transportClient.prepareIndex("ems","emp","10").setSource().get();这一行需要加上index type id三个参数,就是("ems","emp","10")

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值