Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/357.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 无法从Elastic 6.0:“;错误”;:”;不支持内容类型标题[text/plain]””;状态”;:406_Java_<img Src="//i.stack.imgur.com/RUiNP.png" Height="16" Width="18" Alt="" Class="sponsor Tag Img">elasticsearch - Fatal编程技术网 elasticsearch,Java,elasticsearch" /> elasticsearch,Java,elasticsearch" />

Java 无法从Elastic 6.0:“;错误”;:”;不支持内容类型标题[text/plain]””;状态”;:406

Java 无法从Elastic 6.0:“;错误”;:”;不支持内容类型标题[text/plain]””;状态”;:406,java,elasticsearch,Java,elasticsearch,我用java创建了一个客户机,希望从索引中获取查询结果,但出现了406错误: “不支持内容类型标题[文本/普通],”状态:406 Java平台:1.6 ES版本:6.0 下面是代码片段: Client clientInstance = Client.create(); clientInstance.addFilter(new HTTPBasicAuthFilter("", "")); WebResource webResource = clientInstance.resource

我用java创建了一个客户机,希望从索引中获取查询结果,但出现了406错误: “不支持内容类型标题[文本/普通],”状态:406

Java平台:1.6

ES版本:6.0

下面是代码片段:

  Client clientInstance = Client.create();
  clientInstance.addFilter(new HTTPBasicAuthFilter("", ""));
 WebResource webResource =
  clientInstance.resource("http://hostname:9200/indexname/_search");
ClientResponse response=webResource.entity(dsl).accept("application/json").get(ClientResponse.class); 
String result = response.getEntity(String.class);
我在Kibana中使用dsl,可以得到正确的查询结果。但它在java中没有得到正确的响应,并抛出406错误


如何解决此问题?非常感谢

您只需为
应用程序/json
mime类型添加另一个
内容类型
HTTP请求头,因为您正在发送一些json,ES不再猜测您的内容类型:

ClientResponse response = webResource
    .entity(dsl)
    .header("Content-type", "application/json")       <--- add this 
    .accept("application/json")
    .get(ClientResponse.class); 
ClientResponse-response=webResource
.实体(dsl)

.header(“Content type”、“application/json”)您只需为
application/json
mime类型添加另一个
Content type
HTTP请求头,因为您正在发送一些json,ES不再猜测您的内容类型:

ClientResponse response = webResource
    .entity(dsl)
    .header("Content-type", "application/json")       <--- add this 
    .accept("application/json")
    .get(ClientResponse.class); 
ClientResponse-response=webResource
.实体(dsl)

.header(“内容类型”、“应用程序/json”)非常感谢您的回答,它完美地解决了这个问题。太棒了,很高兴它有帮助!您在哪里进行此修改?@dunPushedthatPanicButton不确定您在问什么如果有人在使用jmeter并遇到相同的错误,请添加“HTTP头管理器”并添加“Name:Content-type-Valueapplication/json”,然后运行测试非常感谢您的回答,它完美地解决了问题。太棒了,很高兴它提供了帮助!您在哪里进行此修改?@dunPushedthatPanicButton不确定您在问什么如果有人正在使用jmeter并遇到相同的错误,请添加“HTTP头管理器”并添加“Name:Content-type-Valueapplication/json”,然后运行测试