# Issue while using transport client

**URL:** https://discuss.elastic.co/t/issue-while-using-transport-client/96583
**Category:** Elasticsearch
**Created:** [August 10, 2017, 10:11am UTC](https://discuss.elastic.co/t/issue-while-using-transport-client/96583 "2017-08-10T10:11:35Z")
**Posts on this page:** 11
**Page:** 1

<div class="post-metadata">

### Author: ![Neetu](https://avatars.discourse-cdn.com/v4/letter/n/b5e925/32.png) [@Neetu](https://discuss.elastic.co/u/Neetu)
#### Post date: [August 10, 2017, 10:11am UTC](https://discuss.elastic.co/t/issue-while-using-transport-client/96583/1 "2017-08-10T10:11:36Z")

</div>

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 .

---

<div class="post-metadata">

### Author: ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)
#### Post date: [August 10, 2017, 10:32am UTC](https://discuss.elastic.co/t/issue-while-using-transport-client/96583/2 "2017-08-10T10:32:47Z")

</div>

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

---

<div class="post-metadata">

### Author: ![Neetu](https://avatars.discourse-cdn.com/v4/letter/n/b5e925/32.png) [@Neetu](https://discuss.elastic.co/u/Neetu)
#### Post date: [August 17, 2017, 12:17pm UTC](https://discuss.elastic.co/t/issue-while-using-transport-client/96583/3 "2017-08-17T12:17:18Z")

</div>

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 .

---

<div class="post-metadata">

### Author: ![xavierfacq](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/xavierfacq/32/8744_2.png) [@xavierfacq](https://discuss.elastic.co/u/xavierfacq)
#### Post date: [August 17, 2017, 12:39pm UTC](https://discuss.elastic.co/t/issue-while-using-transport-client/96583/4 "2017-08-17T12:39:51Z")

</div>

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

---

<div class="post-metadata">

### Author: ![Neetu](https://avatars.discourse-cdn.com/v4/letter/n/b5e925/32.png) [@Neetu](https://discuss.elastic.co/u/Neetu)
#### Post date: [August 18, 2017, 6:17am UTC](https://discuss.elastic.co/t/issue-while-using-transport-client/96583/5 "2017-08-18T06:17:08Z")

</div>

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 .

---

<div class="post-metadata">

### Author: ![xavierfacq](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/xavierfacq/32/8744_2.png) [@xavierfacq](https://discuss.elastic.co/u/xavierfacq)
#### Post date: [August 18, 2017, 7:45am UTC](https://discuss.elastic.co/t/issue-while-using-transport-client/96583/6 "2017-08-18T07:45:09Z")

</div>

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 :

> [@Neetu](#):
>
> but iam not able to get search response in proper json format .

Please, provide more details.

---

<div class="post-metadata">

### Author: ![Neetu](https://avatars.discourse-cdn.com/v4/letter/n/b5e925/32.png) [@Neetu](https://discuss.elastic.co/u/Neetu)
#### Post date: [August 18, 2017, 8:40am UTC](https://discuss.elastic.co/t/issue-while-using-transport-client/96583/7 "2017-08-18T08:40:20Z")

</div>

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

---

<div class="post-metadata">

### Author: ![xavierfacq](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/xavierfacq/32/8744_2.png) [@xavierfacq](https://discuss.elastic.co/u/xavierfacq)
#### Post date: [August 18, 2017, 8:49am UTC](https://discuss.elastic.co/t/issue-while-using-transport-client/96583/8 "2017-08-18T08:49:57Z")

</div>

> [@Neetu](#):
>
> 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

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 ?

> [@Neetu](#):
>
> i cant see the query keyword in this jSON response . how can i retrieve it .

To retrieve a field from a hit you can use :

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

```

---

<div class="post-metadata">

### Author: ![Neetu](https://avatars.discourse-cdn.com/v4/letter/n/b5e925/32.png) [@Neetu](https://discuss.elastic.co/u/Neetu)
#### Post date: [August 18, 2017, 11:34am UTC](https://discuss.elastic.co/t/issue-while-using-transport-client/96583/9 "2017-08-18T11:34:13Z")

</div>

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 .

---

<div class="post-metadata">

### Author: ![xavierfacq](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/xavierfacq/32/8744_2.png) [@xavierfacq](https://discuss.elastic.co/u/xavierfacq)
#### Post date: [August 18, 2017, 12:40pm UTC](https://discuss.elastic.co/t/issue-while-using-transport-client/96583/10 "2017-08-18T12:40:06Z")

</div>

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°/

> [@Neetu](#):
>
> how can i get other fields like source

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

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

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)
#### Post date: [September 15, 2017, 12:40pm UTC](https://discuss.elastic.co/t/issue-while-using-transport-client/96583/11 "2017-09-15T12:40:16Z")

</div>

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