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

Elasticsearch error - While trying to search contents in the attachment

我正在使用摄取附件处理器插件为我的 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"));
}

请找到我已经索引的文档

{
  "_index": "attach_local",
  "_type": "doc",
  "_id": "106",
  "_version": 1,
  "found": true,
  "_source": {
    "resume": "1MzUgZg0KMDAwMDAwMDAwMCA2NTUzNSBmDQowMDAwMDAxODg1IDAwMDAwIG4NCjAwMDAwMDIxMzIgMDAwMDAgbg0KMDAwMDA4NTIzNiAwMDAwMCBuDQp0cmFpbGVyDQo8PC9TaXplIDIwL1Jvb3QgMSAwIFIvSW5mbyA5IDAgUi9JRFs8NDlEMTEzNzA1QjE0RDc0NUI4MkQ4NzhDODZFMzEzREU+PDQ5RDExMzcwNUIxNEQ3NDVCODJEODc4Qzg2RTMxM0RFPl0gPj4NCnN0YXJ0eHJlZg0KODU1MTMNCiUlRU9GDQp4cmVmDQowIDANCnRyYWlsZXINCjw8L1NpemUgMjAvUm9vdCAxIDAgUi9JbmZvIDkgMCBSL0lEWzw0OUQxMTM3MDVCMTRENzQ1QjgyRDg3OEM4NkUzMTNERT48NDlEMTEzNzA1QjE0RDc0NUI4MkQ4NzhDODZFMzEzREU+XSAvUHJldiA4NTUxMy9YUmVmU3RtIDg1MjM2Pj4NCnN0YXJ0eHJlZg0KODYwNjkNCiUlRU9G",
    "attachment": {
      "date": "2018-06-21T10:50:01Z",
      "content_type": "application/pdf",
      "author": "Karthikeyan A S",
      "language": "sv",
      "content": "My first Elastic Search attachment using ingest-attachment plugin. Karthikeyan",
      "content_length": 71
    },
    "postDate": "2018-06-21T10:53:53.161Z",
    "Name": "Karthikeyan"
  }
}

请找出下面出现的错误

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.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"
        }
      }
    }
  }
}

我正在使用 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"
        }
      }
    }
  }
}