Document search using Rest High Level Client

I am trying to upload a document index it and search within the document but i am not able to. I am using Rest High Level Client. I have added ingest plugin. I think i'm not using the proper way to index the document. Can anyone help me to achieve this.

but i am not able to

You'll need to be more specific than that.

What exactly have you tried, and what is going wrong?

1 Like

I'm uploading a file and with that i'm passing few fields. And i want index that.

String base64Content = Base64.encodeBase64String(file.get());
XContentBuilder content = null;
content = XContentFactory.jsonBuilder();
content.startObject();
content.field("Module", "Knowledge");
content.field(base64Content);
content.field(entityId);
content.field("Id", tKnowledge.getId());
content.field("Archive", tKnowledge.getArchive());
content.endObject();

		public static void indexKnowledgeDocument(String index, String type, XContentBuilder content, String id) {
	RestHighLevelClient client = IndexUtils.getIndexClient();
	PutPipelineRequest pipelineRequest = new PutPipelineRequest(id,content);
	try {
		AcknowledgedResponse response = client.ingest().putPipeline(pipelineRequest, RequestOptions.DEFAULT);
	} catch (IOException e) {
		e.printStackTrace();
	}
	try {
		client.close();
	} catch (IOException e) {
		e.printStackTrace();
	}		
}

when im passing the content im passing with the other fields too. for indexing document only should i pass the file or with the other fields also can i pass?

If what im doing is not the proper way then what is the way to index a document and search from it.

The PutPipelineRequest is used to store a pipeline not a document.

You want to use the Index API.

I have a module called knowledge. I'm creating an index request with all other properties, one particular property is an attachment, it can be word/pdf and i want to search inside that attachment document also. Before i was using mapper attachments plugin. I saw that its replaced with ingest plugin now, So i was trying like how i have showed above. So what i need to follow to search in attachments,
https://www.elastic.co/guide/en/elasticsearch/client/java-rest/6.4/java-rest-high-document-index.html
or
https://www.elastic.co/guide/en/elasticsearch/reference/6.4/ingest-apis.html

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.