ElasticSearch grammar

450 views
Skip to first unread message

rich...@gmail.com

unread,
Nov 17, 2016, 7:18:43 AM11/17/16
to PEG.js: Parser Generator for JavaScript
Hello,
does there happen to already exist a grammar for ElasticSearch queries?
The closest I found was for Lucene queries (https://github.com/thoward/lucene-query-parser.js), which seems a good start if one does not exist.
Richard

Michel Krämer

unread,
Nov 17, 2016, 1:35:42 PM11/17/16
to rich...@gmail.com, PEG.js: Parser Generator for JavaScript
Hi Richard!

AFAIK Elasticsearch queries are written in JSON, so you just need a JSON parser. Can you give us an example of what you are trying to parse? Thanks.

Michel
> --
> You received this message because you are subscribed to the Google Groups "PEG.js: Parser Generator for JavaScript" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to pegjs+un...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

rich...@gmail.com

unread,
Nov 17, 2016, 9:20:45 PM11/17/16
to PEG.js: Parser Generator for JavaScript, rich...@gmail.com
Thanks for reply!

Here is an example of an ElasticSearch query:
type:Person employments.{role.name:"CEO" employer.name:"Microsoft"} age>40 has:emailAddresses sortBy:location.city.name

Michel Krämer

unread,
Nov 18, 2016, 2:25:23 AM11/18/16
to rich...@gmail.com, PEG.js: Parser Generator for JavaScript
Hi!

OK. I see. You're talking about the query string syntax, right?
https://www.elastic.co/guide/en/elasticsearch/reference/5.0/query-dsl-query-string-query.html#query-string-syntax

I don't know a parser based on PEG.js for this syntax yet. Sorry.

I had a look at the Elasticsearch source code, however, and as far as I can see they just forward the query string to Lucene, so the syntax should be the same:

https://github.com/elastic/elasticsearch/blob/master/core/src/main/java/org/elasticsearch/index/query/QueryStringQueryBuilder.java#L1026-L1032

But I don't have very much experience with query strings in Elasticsearch as I usually use the JSON Query DSL, so I might be totally wrong :-)

Michel

rich...@gmail.com

unread,
Nov 18, 2016, 7:31:46 AM11/18/16
to PEG.js: Parser Generator for JavaScript, rich...@gmail.com
> OK. I see. You're talking about the query string syntax, right?

ah yes, that is the term I should be using.

I found the Lucene grammar does not support Elasticsearch nested queries, so planned to try expanding this grammar unless found a better option.

Reply all
Reply to author
Forward
0 new messages