Using JSON parsers internally

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,

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,

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,