# Using JSON parsers internally

**URL:** <https://discuss.elastic.co/t/using-json-parsers-internally/4789>\
**Category:** Elasticsearch\
**Created:** [July 6, 2011, 11:04am UTC](https://discuss.elastic.co/t/using-json-parsers-internally/4789 "2011-07-06T11:04:13Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![melix](https://avatars.discourse-cdn.com/v4/letter/m/b38774/32.png) [@melix](https://discuss.elastic.co/u/melix)\
**Post date:** [July 6, 2011, 11:04am UTC](https://discuss.elastic.co/t/using-json-parsers-internally/4789/1 "2011-07-06T11:04:13Z")

</div>

Hi,

I was wondering if there was a way to use ElasticSearch internal parsers  
to build a search query. Basically, I'm using the Java API to create a  
search request, through SearchRequestBuilder, and at some point I'd like  
to be able to add facets which are coming in the form of JSON strings,  
for example : { "tags" : { "terms" : {"field" : "tags"} } }

This is because I have a custom query format which looks like ES JSON  
format, but wrapped in a larger object and subtle differences. So  
basically I'd like to obtain an AbstractFacetBuilder instance from a  
JSON string. Is it possible ?

Thanks,

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [July 6, 2011, 4:11pm UTC](https://discuss.elastic.co/t/using-json-parsers-internally/4789/2 "2011-07-06T16:11:21Z")

</div>

No, there is no way to parse a request into the relevant Java builders. But, you can actually send "two" search requests, one as the source, and one called "extra" source, and they get merged, so possibly use the "static" request as the source, and your additional ones as the extra source (if I understood the question correctly).

On Wednesday, July 6, 2011 at 2:04 PM, Cédric Champeau wrote:

> Hi,
> 
> I was wondering if there was a way to use Elasticsearch internal parsers  
> to build a search query. Basically, I'm using the Java API to create a  
> search request, through SearchRequestBuilder, and at some point I'd like  
> to be able to add facets which are coming in the form of JSON strings,  
> for example : { "tags" : { "terms" : {"field" : "tags"} } }
> 
> This is because I have a custom query format which looks like ES JSON  
> format, but wrapped in a larger object and subtle differences. So  
> basically I'd like to obtain an AbstractFacetBuilder instance from a  
> JSON string. Is it possible ?
> 
> Thanks,

---

<div class="post-metadata">

**Author:** ![melix](https://avatars.discourse-cdn.com/v4/letter/m/b38774/32.png) [@melix](https://discuss.elastic.co/u/melix)\
**Post date:** [July 6, 2011, 4:26pm UTC](https://discuss.elastic.co/t/using-json-parsers-internally/4789/3 "2011-07-06T16:26:55Z")

</div>

Ok, that's what I thought. In fact I'm using Jackson to parse a custom  
query language which is converted to an ES query thanks to the Java  
builder API. In some places, I'd like to use the "raw" json format from  
ES, and facets is an example (like highlights). I suspected the  
FacetParseElement class to be my friend but I discovered that it  
actually built a FacetCollector and is used in a node for immediate  
execution.

As I want to avoid "duplicating" code (that is to say writing my own  
JSON parsers for facets where they exist in ES), I wanted to be sure  
there wasn't any other way.

I'll try to do something with the extra source and let you know.

Le 06/07/2011 18:11, Shay Banon a Ã©crit :

> No, there is no way to parse a request into the relevant Java  
> builders. But, you can actually send "two" search requests, one as the  
> source, and one called "extra" source, and they get merged, so  
> possibly use the "static" request as the source, and your additional  
> ones as the extra source (if I understood the question correctly).
> 
> On Wednesday, July 6, 2011 at 2:04 PM, CÃ©dric Champeau wrote:
> 
> > Hi,
> > 
> > I was wondering if there was a way to use Elasticsearch internal parsers  
> > to build a search query. Basically, I'm using the Java API to create a  
> > search request, through SearchRequestBuilder, and at some point I'd like  
> > to be able to add facets which are coming in the form of JSON strings,  
> > for example : { "tags" : { "terms" : {"field" : "tags"} } }
> > 
> > This is because I have a custom query format which looks like ES JSON  
> > format, but wrapped in a larger object and subtle differences. So  
> > basically I'd like to obtain an AbstractFacetBuilder instance from a  
> > JSON string. Is it possible ?
> > 
> > Thanks,

---

<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:01am UTC](https://discuss.elastic.co/t/using-json-parsers-internally/4789/4 "2017-07-06T04:01:34Z")

</div>


