# How do I process the output of elasticsearch?

**URL:** <https://discuss.elastic.co/t/how-do-i-process-the-output-of-elasticsearch/8522>\
**Category:** Elasticsearch\
**Created:** [July 26, 2012, 10:10am UTC](https://discuss.elastic.co/t/how-do-i-process-the-output-of-elasticsearch/8522 "2012-07-26T10:10:25Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![rami\_sellami](https://avatars.discourse-cdn.com/v4/letter/r/e495f1/32.png) [@rami\_sellami](https://discuss.elastic.co/u/rami_sellami)\
**Post date:** [July 26, 2012, 10:10am UTC](https://discuss.elastic.co/t/how-do-i-process-the-output-of-elasticsearch/8522/1 "2012-07-26T10:10:25Z")

</div>

Dear all,

I want to know whether there is a way to return as output a part of the  
JSON documents and not the whole JSON documents.

I give you an example (This is the supposed result):

{"menu": {  
"id": "file",  
"value": "File",  
"popup": {  
"menuitem": [  
{"value": "New", "onclick": "CreateNewDoc()"},  
{"value": "Open", "onclick": "OpenDoc()"},  
{"value": "Close", "onclick": "CloseDoc()"}  
]  
}  
}}

In my case I want to return only a part of the JSON document:

"menuitem": [  
{"value": "New", "onclick": "CreateNewDoc()"},  
{"value": "Open", "onclick": "OpenDoc()"},  
{"value": "Close", "onclick": "CloseDoc()"}  
]

NB: I am using couchDB to the document database.

Could you please help me?

Best regards,  
Rami Sellami

---

<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:** [July 26, 2012, 11:10am UTC](https://discuss.elastic.co/t/how-do-i-process-the-output-of-elasticsearch/8522/2 "2012-07-26T11:10:19Z")

</div>

Have a look at

> **[Elasticsearch Platform — Find real-time answers at scale](https://www.elastic.co)**
>
> Power insights and outcomes with the Elasticsearch Platform and AI. See into your data and find answers that matter with enterprise solutions designed to help you build, observe, and protect. Try Elasticsearch free today.

[http://www.elasticsearch.org/guide/reference/api/search/script-fields.html](http://www.elasticsearch.org/guide/reference/api/search/script-fields.html)  
It should help you to return a field instead of your \_source field.

HTH  
David.

Le 26 juillet 2012 à 12:10, rami sellami [sel.rami@gmail.com](mailto:sel.rami@gmail.com) a écrit :

> Dear all,
> 
> I want to know whether there is a way to return as output a part of the JSON  
> documents and not the whole JSON documents.
> 
> I give you an example (This is the supposed result):
> 
> {"menu": {  
> "id": "file",  
> "value": "File",  
> "popup": {  
> "menuitem": [  
> {"value": "New", "onclick": "CreateNewDoc()"},  
> {"value": "Open", "onclick": "OpenDoc()"},  
> {"value": "Close", "onclick": "CloseDoc()"}  
> ]  
> }  
> }}
> 
> In my case I want to return only a part of the JSON document:
> 
> "menuitem": [  
> {"value": "New", "onclick": "CreateNewDoc()"},  
> {"value": "Open", "onclick": "OpenDoc()"},  
> {"value": "Close", "onclick": "CloseDoc()"}  
> ]
> 
> NB: I am using couchDB to the document database.
> 
> Could you please help me?
> 
> Best regards,  
> Rami Sellami

--  
David Pilato  
[http://www.scrutmydocs.org/](http://www.scrutmydocs.org/)  
[http://dev.david.pilato.fr/](http://dev.david.pilato.fr/)  
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

---

<div class="post-metadata">

**Author:** ![rami\_sellami](https://avatars.discourse-cdn.com/v4/letter/r/e495f1/32.png) [@rami\_sellami](https://discuss.elastic.co/u/rami_sellami)\
**Post date:** [July 26, 2012, 2:22pm UTC](https://discuss.elastic.co/t/how-do-i-process-the-output-of-elasticsearch/8522/3 "2012-07-26T14:22:08Z")

</div>

Thank you David.

I have a mistake, could you check with me please ?

So this a sample of a document :  
{  
"lastName": "Sellami",  
"firstName": "Rami",  
"gender": "Male"  
}

And this is the command :  
curl -XGET [http://localhost:9200/rami/rami/\_search?pretty=1](http://localhost:9200/rami/rami/_search?pretty=1) -d '{  
"fields" : ["Gender"],  
"query" : {  
"query\_string" :{"query" : "Male"}  
},  
"script\_fields" : {  
"test1" : {  
"script" : "doc['Gender'].value"  
}}  
}'  
What is wron with that??

Le jeudi 26 juillet 2012 13:10:19 UTC+2, David Pilato a écrit :

> Have a look at  
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/api/search/script-fields.html)
> 
> It should help you to return a field instead of your \_source field.
> 
> HTH
> 
> David.
> 
> Le 26 juillet 2012 à 12:10, rami sellami [sel.rami@gmail.com](mailto:sel.rami@gmail.com) a écrit :
> 
> Dear all,
> 
> I want to know whether there is a way to return as output a part of the  
> JSON documents and not the whole JSON documents.
> 
> I give you an example (This is the supposed result):
> 
> {"menu": {  
> "id": "file",  
> "value": "File",  
> "popup": {  
> "menuitem": [  
> {"value": "New", "onclick": "CreateNewDoc()"},  
> {"value": "Open", "onclick": "OpenDoc()"},  
> {"value": "Close", "onclick": "CloseDoc()"}  
> ]  
> }  
> }}
> 
> In my case I want to return only a part of the JSON document:
> 
> "menuitem": [  
> {"value": "New", "onclick": "CreateNewDoc()"},  
> {"value": "Open", "onclick": "OpenDoc()"},  
> {"value": "Close", "onclick": "CloseDoc()"}  
> ]
> 
> NB: I am using couchDB to the document database.
> 
> Could you please help me?
> 
> Best regards,  
> Rami Sellami
> 
> --  
> David Pilato  
> [http://www.scrutmydocs.org/](http://www.scrutmydocs.org/)  
> [http://dev.david.pilato.fr/](http://dev.david.pilato.fr/)  
> Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

---

<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:** [July 26, 2012, 2:33pm UTC](https://discuss.elastic.co/t/how-do-i-process-the-output-of-elasticsearch/8522/4 "2012-07-26T14:33:01Z")

</div>

Pb is Gender vs gender

David.

Le 26 juillet 2012 à 16:22, rami sellami [sel.rami@gmail.com](mailto:sel.rami@gmail.com) a écrit :

> Thank you David.
> 
> I have a mistake, could you check with me please ?
> 
> So this a sample of a document :  
> {  
> "lastName": "Sellami",  
> "firstName": "Rami",  
> "gender": "Male"  
> }
> 
> And this is the command :  
> curl -XGET [http://localhost:9200/rami/rami/\_search?pretty=1](http://localhost:9200/rami/rami/_search?pretty=1) -d '{  
> "fields" : ["Gender"],  
> "query" : {  
> "query\_string" :{"query" : "Male"}  
> },  
> "script\_fields" : {  
> "test1" : {  
> "script" : "doc['Gender'].value"  
> }}  
> }'  
> What is wron with that??
> 
> Le jeudi 26 juillet 2012 13:10:19 UTC+2, David Pilato a écrit :
> 
> > > Have a look at  
> > > [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/api/search/script-fields.html)  
> > > [http://www.elasticsearch.org/guide/reference/api/search/script-fields.html](http://www.elasticsearch.org/guide/reference/api/search/script-fields.html)  
> > > It should help you to return a field instead of your \_source field.
> > 
> > HTH  
> > David.
> > 
> > Le 26 juillet 2012 à 12:10, rami sellami \<  
> > [http://www.elasticsearch.org/guide/reference/api/search/script-fields.html](http://www.elasticsearch.org/guide/reference/api/search/script-fields.html)  
> > [sel.rami@gmail.com](mailto:sel.rami@gmail.com) [mailto:sel.rami@gmail.com](mailto:sel.rami@gmail.com) \> a écrit :
> > 
> > ```
> > > > > Dear all,
> > 
> > ```
> > 
> > > ```
> > > I want to know whether there is a way to return as output a part of
> > > 
> > > ```
> > > 
> > > the JSON documents and not the whole JSON documents.
> > > 
> > > ```
> > > I give you an example (This is the supposed result):
> > > 
> > > {"menu": {
> > > "id": "file",
> > > "value": "File",
> > > "popup": {
> > > "menuitem": [
> > > {"value": "New", "onclick": "CreateNewDoc()"},
> > > {"value": "Open", "onclick": "OpenDoc()"},
> > > {"value": "Close", "onclick": "CloseDoc()"}
> > > ]
> > > }
> > > }}
> > > 
> > > In my case I want to return only a part of the JSON document:
> > > 
> > > "menuitem": [
> > > {"value": "New", "onclick": "CreateNewDoc()"},
> > > {"value": "Open", "onclick": "OpenDoc()"},
> > > {"value": "Close", "onclick": "CloseDoc()"}
> > > ]
> > > 
> > > NB: I am using couchDB to the document database.
> > > 
> > > Could you please help me?
> > > 
> > > Best regards,
> > > Rami Sellami
> > > 
> > > ```
> > > 
> > > > >
> > 
> > --  
> > David Pilato  
> > [http://www.scrutmydocs.org/](http://www.scrutmydocs.org/) [http://www.scrutmydocs.org/](http://www.scrutmydocs.org/)  
> > [http://dev.david.pilato.fr/](http://dev.david.pilato.fr/) [http://dev.david.pilato.fr/](http://dev.david.pilato.fr/)  
> > Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs
> > 
> > >

--  
David Pilato  
[http://www.scrutmydocs.org/](http://www.scrutmydocs.org/)  
[http://dev.david.pilato.fr/](http://dev.david.pilato.fr/)  
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

---

<div class="post-metadata">

**Author:** ![rami\_sellami](https://avatars.discourse-cdn.com/v4/letter/r/e495f1/32.png) [@rami\_sellami](https://discuss.elastic.co/u/rami_sellami)\
**Post date:** [July 26, 2012, 2:50pm UTC](https://discuss.elastic.co/t/how-do-i-process-the-output-of-elasticsearch/8522/5 "2012-07-26T14:50:08Z")

</div>

No it's no the problem, even though I changed it still the same error :

{  
"took" : 14,  
"timed\_out" : false,  
"\_shards" : {  
"total" : 5,  
"successful" : 3,  
"failed" : 2,  
"failures" : [ {  
"status" : 500,  
"reason" : "CompileException[[Error: No field found for  
[org.elasticsearch.index.field.data.strings.StringDocFieldData@4fc9584f] in  
mapping with types [rami]]\n[Near : {... doc[Gender].value  
....}]\n ^\n[Line: 1, Column: 1]]; nested:  
ElasticSearchIllegalArgumentException[No field found for  
[org.elasticsearch.index.field.data.strings.StringDocFieldData@4fc9584f] in  
mapping with types [rami]]; "  
}, {  
"status" : 500,  
"reason" : "CompileException[[Error: No field found for  
[org.elasticsearch.index.field.data.strings.StringDocFieldData@182a3bb3] in  
mapping with types [rami]]\n[Near : {... doc[Gender].value  
....}]\n ^\n[Line: 1, Column: 1]]; nested:  
ElasticSearchIllegalArgumentException[No field found for  
[org.elasticsearch.index.field.data.strings.StringDocFieldData@182a3bb3] in  
mapping with types [rami]]; "  
} ]  
},  
"hits" : {  
"total" : 2,  
"max\_score" : 0.30935922,  
"hits" :   
}  
}

Le jeudi 26 juillet 2012 16:33:01 UTC+2, David Pilato a écrit :

> Pb is Gender vs gender
> 
> David.
> 
> Le 26 juillet 2012 à 16:22, rami sellami [sel.rami@gmail.com](mailto:sel.rami@gmail.com) a écrit :
> 
> Thank you David.
> 
> I have a mistake, could you check with me please ?
> 
> So this a sample of a document :  
> {  
> "lastName": "Sellami",  
> "firstName": "Rami",  
> "gender": "Male"  
> }
> 
> And this is the command :  
> curl -XGET [http://localhost:9200/rami/rami/\_search?pretty=1](http://localhost:9200/rami/rami/_search?pretty=1) -d '{  
> "fields" : ["Gender"],  
> "query" : {  
> "query\_string" :{"query" : "Male"}  
> },  
> "script\_fields" : {  
> "test1" : {  
> "script" : "doc['Gender'].value"  
> }}  
> }'  
> What is wron with that??
> 
> Le jeudi 26 juillet 2012 13:10:19 UTC+2, David Pilato a écrit :
> 
> Have a look at  
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/api/search/script-fields.html)
> 
> It should help you to return a field instead of your \_source field.
> 
> HTH
> 
> David.
> 
> Le 26 juillet 2012 à 12:10, rami sellami \<[http://www.elasticsearch.org/guide/reference/api/search/script-fields.html](http://www.elasticsearch.org/guide/reference/api/search/script-fields.html)  
> [sel.rami@gmail.com](mailto:sel.rami@gmail.com)\> a écrit :
> 
> Dear all,
> 
> I want to know whether there is a way to return as output a part of the  
> JSON documents and not the whole JSON documents.
> 
> I give you an example (This is the supposed result):
> 
> {"menu": {  
> "id": "file",  
> "value": "File",  
> "popup": {  
> "menuitem": [  
> {"value": "New", "onclick": "CreateNewDoc()"},  
> {"value": "Open", "onclick": "OpenDoc()"},  
> {"value": "Close", "onclick": "CloseDoc()"}  
> ]  
> }  
> }}
> 
> In my case I want to return only a part of the JSON document:
> 
> "menuitem": [  
> {"value": "New", "onclick": "CreateNewDoc()"},  
> {"value": "Open", "onclick": "OpenDoc()"},  
> {"value": "Close", "onclick": "CloseDoc()"}  
> ]
> 
> NB: I am using couchDB to the document database.
> 
> Could you please help me?
> 
> Best regards,  
> Rami Sellami
> 
> --  
> David Pilato  
> [http://www.scrutmydocs.org/](http://www.scrutmydocs.org/)  
> [http://dev.david.pilato.fr/](http://dev.david.pilato.fr/)  
> Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs
> 
> --  
> David Pilato  
> [http://www.scrutmydocs.org/](http://www.scrutmydocs.org/)  
> [http://dev.david.pilato.fr/](http://dev.david.pilato.fr/)  
> Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

---

<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:** [July 26, 2012, 3:06pm UTC](https://discuss.elastic.co/t/how-do-i-process-the-output-of-elasticsearch/8522/6 "2012-07-26T15:06:39Z")

</div>

I never used scripting but looking at the documentation (

> **[Elasticsearch Platform — Find real-time answers at scale](https://www.elastic.co)**
>
> Power insights and outcomes with the Elasticsearch Platform and AI. See into your data and find answers that matter with enterprise solutions designed to help you build, observe, and protect. Try Elasticsearch free today.

[http://www.elasticsearch.org/guide/reference/api/search/script-fields.html](http://www.elasticsearch.org/guide/reference/api/search/script-fields.html) ),  
it's said:

"Also, the doc[...] notation only allows for simple valued fields (can’t return  
a json object from it) and make sense only on non analyzed or single term based  
fields."

So you probably should write something like:

{  
"query" : {  
...  
},  
"script\_fields" : {  
"test1" : {  
"script" : "\_source.popup"  
}  
}  
}

BTW, it's difficult to follow you and to help you.  
You start with an example which is about a Menu with inline objects (popup) and  
then you send a question that has nothing in common with the first question  
(flat structure with attribute gender).

Hard to follow = hard to provide the best answer.

David.

Le 26 juillet 2012 à 16:50, rami sellami [sel.rami@gmail.com](mailto:sel.rami@gmail.com) a écrit :

> No it's no the problem, even though I changed it still the same error :
> 
> {  
> "took" : 14,  
> "timed\_out" : false,  
> "\_shards" : {  
> "total" : 5,  
> "successful" : 3,  
> "failed" : 2,  
> "failures" : [ {  
> "status" : 500,  
> "reason" : "CompileException[[Error: No field found for  
> [org.elasticsearch.index.field.data.strings.StringDocFieldData@4fc9584f] in  
> mapping with types [rami]]\n[Near : {... doc[Gender].value ....}]\n  
> ^\n[Line: 1, Column: 1]]; nested:  
> ElasticSearchIllegalArgumentException[No field found for  
> [org.elasticsearch.index.field.data.strings.StringDocFieldData@4fc9584f] in  
> mapping with types [rami]]; "  
> }, {  
> "status" : 500,  
> "reason" : "CompileException[[Error: No field found for  
> [org.elasticsearch.index.field.data.strings.StringDocFieldData@182a3bb3] in  
> mapping with types [rami]]\n[Near : {... doc[Gender].value ....}]\n  
> ^\n[Line: 1, Column: 1]]; nested:  
> ElasticSearchIllegalArgumentException[No field found for  
> [org.elasticsearch.index.field.data.strings.StringDocFieldData@182a3bb3] in  
> mapping with types [rami]]; "  
> } ]  
> },  
> "hits" : {  
> "total" : 2,  
> "max\_score" : 0.30935922,  
> "hits" :   
> }  
> }
> 
> Le jeudi 26 juillet 2012 16:33:01 UTC+2, David Pilato a écrit :
> 
> > > Pb is Gender vs gender
> > 
> > David.
> > 
> > Le 26 juillet 2012 à 16:22, rami sellami \< [sel.rami@gmail.com](mailto:sel.rami@gmail.com)  
> > [mailto:sel.rami@gmail.com](mailto:sel.rami@gmail.com) \> a écrit :
> > 
> > ```
> > > > > Thank you David.
> > 
> > ```
> > 
> > > ```
> > > I have a mistake, could you check with me please ?
> > > 
> > > So this a sample of a document :
> > > {
> > > "lastName": "Sellami",
> > > "firstName": "Rami",
> > > "gender": "Male"
> > > }
> > > 
> > > And this is the command :
> > > curl -XGET http://localhost:9200/rami/rami/_search?pretty=1 -d '{
> > > "fields" : ["Gender"],
> > > "query" : {
> > > "query_string" :{"query" : "Male"}
> > > },
> > > "script_fields" : {
> > > "test1" : {
> > > "script" : "doc['Gender'].value"
> > > }}
> > > }'
> > > What is wron with that??
> > > 
> > > Le jeudi 26 juillet 2012 13:10:19 UTC+2, David Pilato a écrit :
> > > 
> > > ```
> > > 
> > > [http://localhost:9200/rami/rami/\_search?pretty=1](http://localhost:9200/rami/rami/_search?pretty=1)  
> > > \> \> \> \> Have a look at  
> > > \> \> \> \> [http://localhost:9200/rami/rami/\_search?pretty=1](http://localhost:9200/rami/rami/_search?pretty=1)  
> > > \> \> \> \> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/api/search/script-fields.html)  
> > > \> \> \> \> [http://www.elasticsearch.org/guide/reference/api/search/script-fields.html](http://www.elasticsearch.org/guide/reference/api/search/script-fields.html)
> > > 
> > > > ```
> > > > It should help you to return a field instead of your _source
> > > > 
> > > > ```
> > > > 
> > > > field.
> > > > 
> > > > ```
> > > > HTH
> > > > David.
> > > > 
> > > > Le 26 juillet 2012 à 12:10, rami sellami <
> > > > 
> > > > ```
> > > > 
> > > > [http://www.elasticsearch.org/guide/reference/api/search/script-fields.html](http://www.elasticsearch.org/guide/reference/api/search/script-fields.html)  
> > > > [sel.rami@gmail.com](mailto:sel.rami@gmail.com) [mailto:sel.rami@gmail.com](mailto:sel.rami@gmail.com) \> a écrit :
> > > > 
> > > > ```
> > > > > > > > > Dear all,
> > > > 
> > > > ```
> > > > 
> > > > > ```
> > > > > I want to know whether there is a way to return as output a
> > > > > 
> > > > > ```
> > > > > 
> > > > > part of the JSON documents and not the whole JSON documents.
> > > > > 
> > > > > ```
> > > > > I give you an example (This is the supposed result):
> > > > > 
> > > > > {"menu": {
> > > > > "id": "file",
> > > > > "value": "File",
> > > > > "popup": {
> > > > > "menuitem": [
> > > > > {"value": "New", "onclick": "CreateNewDoc()"},
> > > > > {"value": "Open", "onclick": "OpenDoc()"},
> > > > > {"value": "Close", "onclick": "CloseDoc()"}
> > > > > ]
> > > > > }
> > > > > }}
> > > > > 
> > > > > In my case I want to return only a part of the JSON document:
> > > > > 
> > > > > "menuitem": [
> > > > > {"value": "New", "onclick": "CreateNewDoc()"},
> > > > > {"value": "Open", "onclick": "OpenDoc()"},
> > > > > {"value": "Close", "onclick": "CloseDoc()"}
> > > > > ]
> > > > > 
> > > > > NB: I am using couchDB to the document database.
> > > > > 
> > > > > Could you please help me?
> > > > > 
> > > > > Best regards,
> > > > > Rami Sellami
> > > > > 
> > > > > > > > > 
> > > > > 
> > > > > ```
> > > > 
> > > > ```
> > > > --
> > > > David Pilato
> > > > http://www.scrutmydocs.org/ <http://www.scrutmydocs.org/>
> > > > http://dev.david.pilato.fr/ <http://dev.david.pilato.fr/>
> > > > Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs
> > > > 
> > > > > > > 
> > > > 
> > > > ```
> > > > 
> > > > >
> > 
> > --  
> > David Pilato  
> > [http://www.scrutmydocs.org/](http://www.scrutmydocs.org/) [http://www.scrutmydocs.org/](http://www.scrutmydocs.org/)  
> > [http://dev.david.pilato.fr/](http://dev.david.pilato.fr/) [http://dev.david.pilato.fr/](http://dev.david.pilato.fr/)  
> > Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs
> > 
> > >

--  
David Pilato  
[http://www.scrutmydocs.org/](http://www.scrutmydocs.org/)  
[http://dev.david.pilato.fr/](http://dev.david.pilato.fr/)  
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

---

<div class="post-metadata">

**Author:** ![rami\_sellami](https://avatars.discourse-cdn.com/v4/letter/r/e495f1/32.png) [@rami\_sellami](https://discuss.elastic.co/u/rami_sellami)\
**Post date:** [July 26, 2012, 3:14pm UTC](https://discuss.elastic.co/t/how-do-i-process-the-output-of-elasticsearch/8522/7 "2012-07-26T15:14:41Z")

</div>

Thank you very much David for your help. It's fine now.

Concerning the changement of the example, I do it because I think that the  
second example is more simple.

Sorry for disturbance

Best Regards  
Rami

2012/7/26 David Pilato [david@pilato.fr](mailto:david@pilato.fr)

> \*\*
> 
> I never used scripting but looking at the documentation (  
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/api/search/script-fields.html) ),  
> it's said:
> 
> "Also, the doc[...] notation only allows for simple valued fields (can’t  
> return a json object from it) and make sense only on non analyzed or single  
> term based fields."
> 
> So you probably should write something like:
> 
> {  
> "query" : {  
> ...  
> },  
> "script\_fields" : {  
> "test1" : {  
> "script" : "\_source.popup"  
> }  
> }  
> }
> 
> BTW, it's difficult to follow you and to help you.
> 
> You start with an example which is about a Menu with inline objects  
> (popup) and then you send a question that has nothing in common with the  
> first question (flat structure with attribute gender).
> 
> Hard to follow = hard to provide the best answer.
> 
> David.
> 
> Le 26 juillet 2012 à 16:50, rami sellami [sel.rami@gmail.com](mailto:sel.rami@gmail.com) a écrit :
> 
> No it's no the problem, even though I changed it still the same error :
> 
> {  
> "took" : 14,  
> "timed\_out" : false,  
> "\_shards" : {  
> "total" : 5,  
> "successful" : 3,  
> "failed" : 2,  
> "failures" : [ {  
> "status" : 500,  
> "reason" : "CompileException[[Error: No field found for  
> [org.elasticsearch.index.field.data.strings.StringDocFieldData@4fc9584f]  
> in mapping with types [rami]]\n[Near : {... doc[Gender].value  
> ....}]\n ^\n[Line: 1, Column: 1]]; nested:  
> ElasticSearchIllegalArgumentException[No field found for  
> [org.elasticsearch.index.field.data.strings.StringDocFieldData@4fc9584f]  
> in mapping with types [rami]]; "  
> }, {  
> "status" : 500,  
> "reason" : "CompileException[[Error: No field found for  
> [org.elasticsearch.index.field.data.strings.StringDocFieldData@182a3bb3]  
> in mapping with types [rami]]\n[Near : {... doc[Gender].value  
> ....}]\n ^\n[Line: 1, Column: 1]]; nested:  
> ElasticSearchIllegalArgumentException[No field found for  
> [org.elasticsearch.index.field.data.strings.StringDocFieldData@182a3bb3]  
> in mapping with types [rami]]; "  
> } ]  
> },  
> "hits" : {  
> "total" : 2,  
> "max\_score" : 0.30935922,  
> "hits" :   
> }  
> }
> 
> Le jeudi 26 juillet 2012 16:33:01 UTC+2, David Pilato a écrit :
> 
> Pb is Gender vs gender
> 
> David.
> 
> Le 26 juillet 2012 à 16:22, rami sellami \< [sel.rami@gmail.com](mailto:sel.rami@gmail.com)\> a écrit :
> 
> Thank you David.
> 
> I have a mistake, could you check with me please ?
> 
> So this a sample of a document :  
> {  
> "lastName": "Sellami",  
> "firstName": "Rami",  
> "gender": "Male"  
> }
> 
> And this is the command :  
> curl -XGET [http://localhost:9200/rami/rami/\_search?pretty=1](http://localhost:9200/rami/rami/_search?pretty=1) -d '{  
> "fields" : ["Gender"],  
> "query" : {  
> "query\_string" :{"query" : "Male"}  
> },  
> "script\_fields" : {  
> "test1" : {  
> "script" : "doc['Gender'].value"  
> }}  
> }'  
> What is wron with that??
> 
> Le jeudi 26 juillet 2012 13:10:19 UTC+2, David Pilato a écrit :  
> [http://localhost:9200/rami/rami/\_search?pretty=1](http://localhost:9200/rami/rami/_search?pretty=1)
> 
> Have a look at [http://localhost:9200/rami/rami/\_search?pretty=1](http://localhost:9200/rami/rami/_search?pretty=1)  
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/api/search/script-fields.html)
> 
> It should help you to return a field instead of your \_source field.
> 
> HTH
> 
> David.
> 
> Le 26 juillet 2012 à 12:10, rami sellami \<[http://www.elasticsearch.org/guide/reference/api/search/script-fields.html](http://www.elasticsearch.org/guide/reference/api/search/script-fields.html)  
> [sel.rami@gmail.com](mailto:sel.rami@gmail.com)\> a écrit :
> 
> Dear all,
> 
> I want to know whether there is a way to return as output a part of the  
> JSON documents and not the whole JSON documents.
> 
> I give you an example (This is the supposed result):
> 
> {"menu": {  
> "id": "file",  
> "value": "File",  
> "popup": {  
> "menuitem": [  
> {"value": "New", "onclick": "CreateNewDoc()"},  
> {"value": "Open", "onclick": "OpenDoc()"},  
> {"value": "Close", "onclick": "CloseDoc()"}  
> ]  
> }  
> }}
> 
> In my case I want to return only a part of the JSON document:
> 
> "menuitem": [  
> {"value": "New", "onclick": "CreateNewDoc()"},  
> {"value": "Open", "onclick": "OpenDoc()"},  
> {"value": "Close", "onclick": "CloseDoc()"}  
> ]
> 
> NB: I am using couchDB to the document database.
> 
> Could you please help me?
> 
> Best regards,  
> Rami Sellami
> 
> --  
> David Pilato  
> [http://www.scrutmydocs.org/](http://www.scrutmydocs.org/)  
> [http://dev.david.pilato.fr/](http://dev.david.pilato.fr/)  
> Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs
> 
> --  
> David Pilato  
> [http://www.scrutmydocs.org/](http://www.scrutmydocs.org/)  
> [http://dev.david.pilato.fr/](http://dev.david.pilato.fr/)  
> Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs
> 
> --  
> David Pilato  
> [http://www.scrutmydocs.org/](http://www.scrutmydocs.org/)  
> [http://dev.david.pilato.fr/](http://dev.david.pilato.fr/)  
> Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

--  
Cordialement,  
Rami Sellami

---

<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:** [July 26, 2012, 3:39pm UTC](https://discuss.elastic.co/t/how-do-i-process-the-output-of-elasticsearch/8522/8 "2012-07-26T15:39:34Z")

</div>

Great. Thanks for the feedback.

David

--

Le 26 juil. 2012 à 17:14, rami sellami [sel.rami@gmail.com](mailto:sel.rami@gmail.com) a écrit :

> Thank you very much David for your help. It's fine now.
> 
> Concerning the changement of the example, I do it because I think that the second example is more simple.
> 
> Sorry for disturbance
> 
> Best Regards  
> Rami
> 
> 2012/7/26 David Pilato [david@pilato.fr](mailto:david@pilato.fr)  
> I never used scripting but looking at the documentation ( [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/api/search/script-fields.html) ), it's said:
> 
> "Also, the doc[...] notation only allows for simple valued fields (can’t return a json object from it) and make sense only on non analyzed or single term based fields."
> 
> So you probably should write something like:  
> {  
> "query" : {  
> ...  
> },
> 
> ```
> "script_fields" : {
> "test1" : {
> 
> "script" : "_source.popup" 
> }
> }
> 
> }
> 
> ```
> 
> BTW, it's difficult to follow you and to help you.  
> You start with an example which is about a Menu with inline objects (popup) and then you send a question that has nothing in common with the first question (flat structure with attribute gender).
> 
> Hard to follow = hard to provide the best answer.
> 
> David.
> 
> Le 26 juillet 2012 à 16:50, rami sellami [sel.rami@gmail.com](mailto:sel.rami@gmail.com) a écrit :
> 
> No it's no the problem, even though I changed it still the same error :
> 
> {  
> "took" : 14,  
> "timed\_out" : false,  
> "\_shards" : {  
> "total" : 5,  
> "successful" : 3,  
> "failed" : 2,  
> "failures" : [ {  
> "status" : 500,  
> "reason" : "CompileException[[Error: No field found for [org.elasticsearch.index.field.data.strings.StringDocFieldData@4fc9584f] in mapping with types [rami]]\n[Near : {... doc[Gender].value ....}]\n ^\n[Line: 1, Column: 1]]; nested: ElasticSearchIllegalArgumentException[No field found for [org.elasticsearch.index.field.data.strings.StringDocFieldData@4fc9584f] in mapping with types [rami]]; "  
> }, {  
> "status" : 500,  
> "reason" : "CompileException[[Error: No field found for [org.elasticsearch.index.field.data.strings.StringDocFieldData@182a3bb3] in mapping with types [rami]]\n[Near : {... doc[Gender].value ....}]\n ^\n[Line: 1, Column: 1]]; nested: ElasticSearchIllegalArgumentException[No field found for [org.elasticsearch.index.field.data.strings.StringDocFieldData@182a3bb3] in mapping with types [rami]]; "  
> } ]  
> },  
> "hits" : {  
> "total" : 2,  
> "max\_score" : 0.30935922,  
> "hits" :   
> }  
> }
> 
> Le jeudi 26 juillet 2012 16:33:01 UTC+2, David Pilato a écrit :  
> Pb is Gender vs gender
> 
> David.
> 
> Le 26 juillet 2012 à 16:22, rami sellami \< [sel.rami@gmail.com](mailto:sel.rami@gmail.com)\> a écrit :
> 
> Thank you David.
> 
> I have a mistake, could you check with me please ?
> 
> So this a sample of a document :  
> {  
> "lastName": "Sellami",  
> "firstName": "Rami",  
> "gender": "Male"  
> }
> 
> And this is the command :  
> curl -XGET [http://localhost:9200/rami/rami/\_search?pretty=1](http://localhost:9200/rami/rami/_search?pretty=1) -d '{  
> "fields" : ["Gender"],  
> "query" : {  
> "query\_string" :{"query" : "Male"}  
> },  
> "script\_fields" : {  
> "test1" : {  
> "script" : "doc['Gender'].value"  
> }}  
> }'  
> What is wron with that??
> 
> Le jeudi 26 juillet 2012 13:10:19 UTC+2, David Pilato a écrit :  
> Have a look at [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/api/search/script-fields.html)  
> It should help you to return a field instead of your \_source field.
> 
> HTH  
> David.
> 
> Le 26 juillet 2012 à 12:10, rami sellami \< [sel.rami@gmail.com](mailto:sel.rami@gmail.com)\> a écrit :
> 
> Dear all,
> 
> I want to know whether there is a way to return as output a part of the JSON documents and not the whole JSON documents.
> 
> I give you an example (This is the supposed result):
> 
> {"menu": {  
> "id": "file",  
> "value": "File",  
> "popup": {  
> "menuitem": [  
> {"value": "New", "onclick": "CreateNewDoc()"},  
> {"value": "Open", "onclick": "OpenDoc()"},  
> {"value": "Close", "onclick": "CloseDoc()"}  
> ]  
> }  
> }}
> 
> In my case I want to return only a part of the JSON document:  
> "menuitem": [  
> {"value": "New", "onclick": "CreateNewDoc()"},  
> {"value": "Open", "onclick": "OpenDoc()"},  
> {"value": "Close", "onclick": "CloseDoc()"}  
> ]
> 
> NB: I am using couchDB to the document database.
> 
> Could you please help me?
> 
> Best regards,  
> Rami Sellami
> 
> --  
> David Pilato  
> [http://www.scrutmydocs.org/](http://www.scrutmydocs.org/)  
> [http://dev.david.pilato.fr/](http://dev.david.pilato.fr/)  
> Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs
> 
> --  
> David Pilato  
> [http://www.scrutmydocs.org/](http://www.scrutmydocs.org/)  
> [http://dev.david.pilato.fr/](http://dev.david.pilato.fr/)  
> Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs
> 
> --  
> David Pilato  
> [http://www.scrutmydocs.org/](http://www.scrutmydocs.org/)  
> [http://dev.david.pilato.fr/](http://dev.david.pilato.fr/)  
> Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs
> 
> --  
> Cordialement,  
> Rami Sellami

---

<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, 3:18am UTC](https://discuss.elastic.co/t/how-do-i-process-the-output-of-elasticsearch/8522/9 "2017-07-06T03:18:55Z")

</div>


