elasticsearch,elastic-stack,Java,elasticsearch,Elastic Stack" /> elasticsearch,elastic-stack,Java,elasticsearch,Elastic Stack" />

Java Elasticsearch错误-尝试搜索附件中的内容时

Java Elasticsearch错误-尝试搜索附件中的内容时,java,elasticsearch,elastic-stack,Java,elasticsearch,Elastic Stack,我使用ingest attachment processor插件为我的pdf文件编制索引,我还可以使用java代码编制索引。现在,我想在elasticsearch中提供的pdf文件中搜索一些内容 我使用下面的查询来搜索文件中的内容,执行此代码时出错 SearchRequest contentSearchRequest = new SearchRequest(ATTACHMENT); SearchSourceBuilder contentSearchSourceBuilder = new Sea

我使用ingest attachment processor插件为我的pdf文件编制索引,我还可以使用java代码编制索引。现在,我想在elasticsearch中提供的pdf文件中搜索一些内容

我使用下面的查询来搜索文件中的内容,执行此代码时出错

SearchRequest contentSearchRequest = new SearchRequest(ATTACHMENT); 
SearchSourceBuilder contentSearchSourceBuilder = new SearchSourceBuilder();
contentSearchRequest.types(TYPE);
QueryBuilder attachmentQB = QueryBuilders.matchQuery("attachment.content", "karthikeyan");
contentSearchSourceBuilder.query(attachmentQB);
contentSearchSourceBuilder.size(50);
searchRequest.source(contentSearchSourceBuilder);
SearchResponse contentSearchResponse = null;
try {
    contentSearchResponse = restHighLevelClient.search(contentSearchRequest);
} catch (IOException e) {
    e.getLocalizedMessage();
}

SearchHit[] contentSearchHits = contentSearchResponse.getHits().getHits();
long contenttotalHits=contentSearchResponse.getHits().totalHits;
System.out.println("condition Total Hits --->"+contenttotalHits);

for (SearchHit contenthit : contentSearchHits) {

    Map<String, Object> sourceAsMap = contenthit.getSourceAsMap();
    System.out.println("----------->"+sourceAsMap.get("resume"));
}
请查找下面我得到的错误

ElasticsearchStatusException[Elasticsearch exception [type=search_phase_execution_exception, reason=all shards failed]]
    at org.elasticsearch.rest.BytesRestResponse.errorFromXContent(BytesRestResponse.java:177)
    at org.elasticsearch.client.RestHighLevelClient.parseEntity(RestHighLevelClient.java:573)
    at org.elasticsearch.client.RestHighLevelClient.parseResponseException(RestHighLevelClient.java:549)
    at java.lang.Thread.run(Thread.java:748)
    Suppressed: org.elasticsearch.client.ResponseException: method [GET], host [http://localhost:9200], URI [/attach_local/doc/_search?typed_keys=true&ignore_unavailable=false&expand_wildcards=open&allow_no_indices=true&search_type=query_then_fetch&batched_reduce_size=512], status line [HTTP/1.1 400 Bad Request]
{"error":{"root_cause":[{"type":"query_shard_exception","reason":"Binary fields do not support searching","index_uuid":"JjE66zAUSKi11FJ_yHVLSA","index":"attach_local"}],"type":"search_phase_execution_exception","reason":"all shards failed","phase":"query","grouped":true,"failed_shards":[{"shard":0,"index":"attach_local","node":"uPLyU7R5RXeirg8XzRqhnA","reason":{"type":"query_shard_exception","reason":"Binary fields do not support searching","index_uuid":"JjE66zAUSKi11FJ_yHVLSA","index":"attach_local"}}]},"status":400}
        at org.elasticsearch.client.RestClient$1.completed(RestClient.java:357)
请查找我的详细信息

PUT attach_local
{
  "mappings" : {
    "doc" : {
      "properties" : {
        "attachment" : {
          "properties" : {
            "content" : {
              "type" : "binary"
            },
            "content_length" : {
              "type" : "long"
            },
            "content_type" : {
              "type" : "text"
            },
            "language" : {
              "type" : "text"
            }
          }
        },
        "resume" : {
          "type" : "text"
        }
      }
    }
  }
}

Am使用Elasticsearch版本6.2.3版本

映射已更改如下,并且工作正常

PUT attach_local
{
  "mappings" : {
    "doc" : {
      "properties" : {
        "attachment" : {
          "properties" : {
            "content" : {
              "type" : "text"
            },
            "content_length" : {
              "type" : "long"
            },
            "content_type" : {
              "type" : "text"
            },
            "language" : {
              "type" : "text"
            }
          }
        },
        "resume" : {
          "type" : "text"
        }
      }
    }
  }
}

将attachment.content的映射更改为text,然后搜索将适用于这种情况。一般来说,在使用ingest attachment processor时,附件的映射将是动态的,这意味着您应该让ES为您推断映射。@sramalingam24-我已将
内容
的映射从
二进制
更改为
文本
,并且工作正常。
PUT attach_local
{
  "mappings" : {
    "doc" : {
      "properties" : {
        "attachment" : {
          "properties" : {
            "content" : {
              "type" : "text"
            },
            "content_length" : {
              "type" : "long"
            },
            "content_type" : {
              "type" : "text"
            },
            "language" : {
              "type" : "text"
            }
          }
        },
        "resume" : {
          "type" : "text"
        }
      }
    }
  }
}