Recently I have been making a lot of use of ElasticSearch (http://
elasticsearch.org) which is a very nice REST layer on top of Lucene.
In the interest of learning more about json-schema, and working more
concretely with it, I decided to try and build a json-schema of the
query DSL :
http://www.elasticsearch.org/guide/reference/query-dsl/
One of the things that I found tricky was the lack of context a lot of
the examples have, because the components of the object can be re-used
in different contexts. The result of this experiment has lead me to
this point :
https://gist.github.com/8887766ca0e7052814b0
As an example the basic query looks as follows :
{
query {
match_all: {}
}
}
Where match_all could be replaced with any of the query objects (the
full list on the guide). Now the tricky part here, is that there
may be only one 'command' inside the query object. Which means the
following should be invalid :
{
query {
match_all: {},
term: { fieldname: 'searchterm' }
}
}
I think I managed to represent that here :
https://gist.github.com/8887766ca0e7052814b0#L143
, whereby it will only match to one of the items,
but it still feels a bit obtuse.
What really throws me however is the fact that the api requires the
use of a property name representing the field on the indexed object to
search
for. The term query above is an ideal example :
http://www.elasticsearch.org/guide/reference/query-dsl/term-query.html
It is one of the possible queries that can be run (of which there can
only be one), and it may only have a single property with a freeform
key, that
may be a string, or one of two different object representations.
The interaction between patternProperties and additionalProperties
alone confuses me, but I am not sure how to represent the limitation
of only
having a single property. Any help would be appreciated.