我正在使用吞食-附件处理器插件来索引我的pdf文件,并能够索引也使用java代码。现在,我想搜索一些内容,在我的pdf文件,这是可在elasticsearch。
正在使用下面的查询搜索文件中的内容,并在执行此代码时出错。
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$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"
}
}
}
}
}使用Elasticsearch版本6.2.3版本
发布于 2018-06-22 11:22:42
映射已被更改如下。,它运行良好。
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"
}
}
}
}
}https://stackoverflow.com/questions/50980315
复制相似问题