# Search always return the original file

**URL:** <https://discuss.elastic.co/t/search-always-return-the-original-file/4038>\
**Category:** Elasticsearch\
**Created:** [March 5, 2011, 4:22am UTC](https://discuss.elastic.co/t/search-always-return-the-original-file/4038 "2011-03-05T04:22:28Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![canal](https://avatars.discourse-cdn.com/v4/letter/c/4bbf92/32.png) [@canal](https://discuss.elastic.co/u/canal)\
**Post date:** [March 5, 2011, 4:22am UTC](https://discuss.elastic.co/t/search-always-return-the-original-file/4038/1 "2011-03-05T04:22:28Z")

</div>

Hello,  
I am able to search binary documents, but the search response always has the  
original file content. How not to get the file content back in the search  
response?

This is how I create the search and build the JSON string:

FieldQueryBuilder builder = new FieldQueryBuilder ("file", keywords);  
SearchResponse searchResponse =  
client.prepareSearch(this.indexName).setSearchType(SearchType.QUERY\_THEN\_FETCH).setQuery(builder).execute().actionGet();

XContentBuilder b = XContentFactory.jsonBuilder();  
b.startObject();  
searchResponse.toXContent(b, ToXContent.EMPTY\_PARAMS);  
b.endObject();  
return b.string();  
thanks,  
canal

---

<div class="post-metadata">

**Author:** ![canal](https://avatars.discourse-cdn.com/v4/letter/c/4bbf92/32.png) [@canal](https://discuss.elastic.co/u/canal)\
**Post date:** [March 5, 2011, 8:42am UTC](https://discuss.elastic.co/t/search-always-return-the-original-file/4038/2 "2011-03-05T08:42:28Z")

</div>

This is my mapping file but the "file" is still returned as part of the search  
result:

{  
document : {  
properties : {  
"file" : { type : "attachment", store: "no" }  
}  
}  
}

This is how I create the index:

String mapping =  
IOUtils.toString(getClass().getResourceAsStream("/test-mapping.json"));  
client.admin().indices().create(new  
CreateIndexRequest(indexName).mapping(indexType, mapping)).actionGet();  
client.admin().cluster().health(new  
ClusterHealthRequest(indexName).waitForYellowStatus()).actionGet();  
Did I miss out anything?

thanks,  
canal

* * *

From: go canal [gocanal@yahoo.com](mailto:gocanal@yahoo.com)  
To: [users@elasticsearch.com](mailto:users@elasticsearch.com)  
Sent: Sat, March 5, 2011 12:22:28 PM  
Subject: search always return the original file

Hello,  
I am able to search binary documents, but the search response always has the  
original file content. How not to get the file content back in the search  
response?

This is how I create the search and build the JSON string:

FieldQueryBuilder builder = new FieldQueryBuilder ("file", keywords);  
SearchResponse searchResponse =  
client.prepareSearch(this.indexName).setSearchType(SearchType.QUERY\_THEN\_FETCH).setQuery(builder).execute().actionGet();

XContentBuilder b = XContentFactory.jsonBuilder();  
b.startObject();  
searchResponse.toXContent(b, ToXContent.EMPTY\_PARAMS);  
b.endObject();  
return b.string();  
thanks,  
canal

---

<div class="post-metadata">

**Author:** ![Lukas\_Vlcek1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/lukas_vlcek1/32/819_2.png) [@Lukas\_Vlcek1](https://discuss.elastic.co/u/Lukas_Vlcek1)\
**Post date:** [March 5, 2011, 8:21pm UTC](https://discuss.elastic.co/t/search-always-return-the-original-file/4038/3 "2011-03-05T20:21:43Z")

</div>

Hi Canal,

you are getting back the document content in the response because it is part  
of the \_source field which is returned for each hit by default. Try to check  
field query  
[Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/api/search/fields.html) to  
selectively return only specific field values.

Regards,  
Lukas

On Sat, Mar 5, 2011 at 9:42 AM, go canal [gocanal@yahoo.com](mailto:gocanal@yahoo.com) wrote:

> This is my mapping file but the "file" is still returned as part of the  
> search result:
> 
> {  
> document : {  
> properties : {  
> "file" : { type : "attachment", store: "no" }  
> }  
> }  
> }
> 
> This is how I create the index:
> 
> String mapping =  
> IOUtils.toString(getClass().getResourceAsStream("/test-mapping.json"));  
> client.admin().indices().create(new  
> CreateIndexRequest(indexName).mapping(indexType, mapping)).actionGet();  
> client.admin().cluster().health(new  
> ClusterHealthRequest(indexName).waitForYellowStatus()).actionGet();
> 
> Did I miss out anything?
> 
> thanks,  
> canal
> 
> * * *
> 
> _From:_ go canal [gocanal@yahoo.com](mailto:gocanal@yahoo.com)  
> _To:_ [users@elasticsearch.com](mailto:users@elasticsearch.com)  
> _Sent:_ Sat, March 5, 2011 12:22:28 PM  
> _Subject:_ search always return the original file
> 
> Hello,  
> I am able to search binary documents, but the search response always has  
> the original file content. How not to get the file content back in the  
> search response?
> 
> This is how I create the search and build the JSON string:
> 
> FieldQueryBuilder builder = new FieldQueryBuilder ("file", keywords);  
> SearchResponse searchResponse =  
> client.prepareSearch(this.indexName).setSearchType(SearchType.QUERY\_THEN\_FETCH).setQuery(builder).execute().actionGet();
> 
> XContentBuilder b = XContentFactory.jsonBuilder();  
> b.startObject();  
> searchResponse.toXContent(b, ToXContent.EMPTY\_PARAMS);  
> b.endObject();  
> return b.string();
> 
> thanks,  
> canal

---

<div class="post-metadata">

**Author:** ![canal](https://avatars.discourse-cdn.com/v4/letter/c/4bbf92/32.png) [@canal](https://discuss.elastic.co/u/canal)\
**Post date:** [March 5, 2011, 11:38pm UTC](https://discuss.elastic.co/t/search-always-return-the-original-file/4038/4 "2011-03-05T23:38:29Z")

</div>

Thank you very much Lukas, it works !  
thanks,  
canal

* * *

From: Lukáš Vlček [lukas.vlcek@gmail.com](mailto:lukas.vlcek@gmail.com)  
To: [users@elasticsearch.com](mailto:users@elasticsearch.com)  
Sent: Sun, March 6, 2011 4:21:43 AM  
Subject: Re: search always return the original file

Hi Canal,

you are getting back the document content in the response because it is part of  
the \_source field which is returned for each hit by default. Try to check field  
query [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/api/search/fields.html) to  
selectively return only specific field values.

Regards,  
Lukas

On Sat, Mar 5, 2011 at 9:42 AM, go canal [gocanal@yahoo.com](mailto:gocanal@yahoo.com) wrote:

This is my mapping file but the "file" is still returned as part of the search  
result:

> {  
> document : {  
> properties : {  
> "file" : { type : "attachment", store: "no" }  
> }  
> }  
> }
> 
> This is how I create the index:
> 
> String mapping =  
> IOUtils.toString(getClass().getResourceAsStream("/test-mapping.json"));  
> client.admin().indices().create(new  
> CreateIndexRequest(indexName).mapping(indexType, mapping)).actionGet();  
> client.admin().cluster().health(new  
> ClusterHealthRequest(indexName).waitForYellowStatus()).actionGet();
> 
> Did I miss out anything?
> 
> thanks,  
> canal

* * *

From: go canal [gocanal@yahoo.com](mailto:gocanal@yahoo.com)

> To: [users@elasticsearch.com](mailto:users@elasticsearch.com)  
> Sent: Sat, March 5, 2011 12:22:28 PM  
> Subject: search always return the original file
> 
> Hello,  
> I am able to search binary documents, but the search response always has the  
> original file content. How not to get the file content back in the search  
> response?
> 
> This is how I create the search and build the JSON string:
> 
> FieldQueryBuilder builder = new FieldQueryBuilder ("file", keywords);  
> SearchResponse searchResponse =  
> client.prepareSearch(this.indexName).setSearchType(SearchType.QUERY\_THEN\_FETCH).setQuery(builder).execute().actionGet();
> 
> XContentBuilder b = XContentFactory.jsonBuilder();  
> b.startObject();  
> searchResponse.toXContent(b, ToXContent.EMPTY\_PARAMS);  
> b.endObject();  
> return b.string();
> 
> thanks,  
> canal

---

<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:** [July 6, 2017, 4:10am UTC](https://discuss.elastic.co/t/search-always-return-the-original-file/4038/5 "2017-07-06T04:10:45Z")

</div>


