Issue while using transport client

HI ,
Iam using transport client 5.4.3 version with elastic search 5.4.3 version and java as 1.8 but iam unable to connect to the server with trasport client .
TransportClient client = new PreBuiltTransportClient(Settings.EMPTY).addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("server"), 9300));

iam getting error in PreBuiltTransportClient as Resource Path Location Type PreBuiltTransportClient cannot be resolved to a type UserRest.java .

can anyone please help me with the correct way to fix this issue . i couldn't find the exact solution for this .

Not possible to help without full details. Specifically full logs.

iam trying to get search response this way as i need to get all the location where this file is stored :
client = new PreBuiltTransportClient(settings).addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("address"), 9300)); QueryBuilder qb = QueryBuilders.boolQuery().must(QueryBuilders.termQuery("file.filename", "J.K.Rowling- Harry Potter and the Sorcerer's Stone.txt"));
SearchResponse scrollResp = client.prepareSearch("ftp_folder")
.addSort(FieldSortBuilder.DOC_FIELD_NAME, SortOrder.ASC)
.setScroll(new TimeValue(60000))
.setQuery(qb)
.setSize(100).execute().actionGet();
System.out.println("scrollResp"+scrollResp);

  but the response format that iam getting is : {"took":307,"timed_out":false,"_shards":{"total":5,"successful":5,"failed":0},"hits":{"total":38,"max_score":2.5529227,"hits":[{"_index":"ftp_public","_type":"doc","_id":"b8f8207a434a4dfc7221a5a4a8a6c3c","_score":2.5529227,"_source":{

"root" : "9f3dcd97c4ec315fa645bcdc815e4",
"virtual" : "/English/Listening /headway beginner",
"real" : "\\ftp\ftp\Public\English\Listening\headway beginner"
}},{"_index":"ftp_public","_type":"doc","_id":"e1fab4a16772714c36138a2dbf31b3e4","_score":2.5529227,"_source":{
"root" : "9f3dcd97c4ec315fa645bcdc815e4",

is this the correct way how iam querying my search ? as i dont think that iam getting the correct response .

First, please, format provided code and json to be readable.

Your query is a TermQuery applied to the field named "file.filename", searching for "J.K.Rowling- Harry Potter and the Sorcerer’s Stone.

addSort(FieldSortBuilder.DOC_FIELD_NAME, SortOrder.ASC)

First param must be the fieldname in your index used to sort. I don't think FieldSortBuilder.DOC_FIELD_NAME can be used.

is this the correct way how iam querying my search ? as i dont think that iam getting the correct response .

If you provide the mapping and what you want to search, we'ill be able to help you. For now it is a little fuzzy...

Hi ,
what iam trying here is ,the documents are already indexed on elastic search server and i need to write a search query to get those documents as a result on based of the query hit . iam trying with the below code

client = new PreBuiltTransportClient(settings).addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("host"), 9300));

		 QueryBuilder qb = QueryBuilders.termQuery("file.filename", "hary potter");
		 SearchResponse scrollResp = client.prepareSearch("ftp_public_fscrawler")
			        .setScroll(new TimeValue(60000))
			        .setQuery(qb)
			        .setSize(100).execute().actionGet();
		 
		  
		 while (true) {
		        //Break condition: No hits are returned
		        if (scrollResp.getHits().getHits().length == 0) {
		            break;
		        }
		        for (SearchHit hit : scrollResp.getHits().getHits()) {
		            JSONObject value = new JSONObject(hit.getSource()); 

but iam not able to get search response in proper json format .

1°/ Do you get response your are looking for ? Do you have SearchHit in your for loop ?

2°/ What do you expect to have when you write :

Please, provide more details.

no iam not able to get the correct response that iam looking for : when iam giving query as :J.K.Rowling- Harry Potter and the Sorcerer's Stone.txt . iam getting json response as below

{
"took" : 306,
"timed_out" : false,
"_shards" : {
"total" : 5,
"successful" : 5,
"failed" : 0
},
"hits" : {
"total" : 23,
"max_score" : 8.506227,
"hits" : [
{
"_index" : "ftp_public_fscrawler_from_russia_folder",
"_type" : "doc",
"_id" : "69db39631b623ad6ab3cc7ec45b8d92",
"_score" : 8.506227,
"_source" : {
"root" : "7a1652c1448c3164dea76c4adfc2ea",
"virtual" : "/English/English Audiobooks/Harry Potter/Harry Potter - Book3",
"real" : "\\ftp\ftp\Public\English\English Audiobooks\Harry Potter\Harry Potter - Book3"
}
},
{
"_index" : "ftp_public_fscrawler_from_russia_folder",
"_type" : "doc",
"_id" : "f5cd60ae3fd2e040bdecc8e3e6949daa",
"_score" : 8.506227,
"_source" : {
"root" : "7a1652c1448c3164dea76c4adfc2ea",
"virtual" : "/English/English Audiobooks/Harry Potter/Harry Potter - Book4",
"real" : "\\ftp\ftp\Public\English\English Audiobooks\Harry Potter\Harry Potter - Book4"
}
},
i cant see the query keyword in this jSON response . how can i retrieve it . when iam checking the same with SENSE then iam getting the correct response

1°/ Do you have a document named "J.K.Rowling- Harry Potter and the Sorcerer’s Stone.txt" ? Is it the one you are expected for ?

2°/ What is the mapping for the field: file.filename ?

To retrieve a field from a hit you can use :

String virtual = (String)hit.getSource().get("virtual")

yes i have this document and i want this to come in search response but if u will check the json response posted above i cant see that to be there . how can i get other fields like source,content from searchquery .
i have tried String virtual = (String)hit.getSource().get("virtual") which is giving me folder location .

Your responses are a little confused...

1°/ There is no reason for your document not to be in results with the following query, if the field file.filename exists

QueryBuilder qb = QueryBuilders.termQuery("file.filename", "harry potter Stone");

2°/

You can retrieve all indexed fields using hit.getSource().get(“you_fieldname");

Please, if you want more help, provide more details, well formated.

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