Review/update/fix query definitions #486
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR is an exhaustive review/update/fix of the 53 query definitions.
Fixing/updating query definitions
Query definitions follow one of 3 different patterns, driven by where the base query fields (
boost
and_name
) appear in the data structure:QueryBase
: all queries that do not target a single field (e.g. boolean query)SinglekeyDictionary<Field, SomeQuery>
: queries where the structure is a single property for the field name, with a nested structure that holds the base fields (e.g. term query)AdditionalProperty<Field, SomeFieldQuery>
: queries where the top-level structure contains a single field name and also the base query fields. Used mostly in geo queries, e.g. geo polygon query.The specification of the query definitions has been verified:
There are however 3 additional validation errors coming from Nest tests where Nest is overly flexible, allowing numbers where strings are the only values that semantically make sense. These tests succeed in Nest because ES is overly lenient and (most often) accepts any primitive type where it expects a string, but we should not encode this leniency in the spec where it doesn't make sense from a semantic perspective.
AdditionalProperty behavior
This PR introduces a new behavior,
AdditionalProperty
, which is toSingleKeyDictionary
whatAdditionalProperties
is toDictionary
: it is used to model field queries, where only one single field can be the target of a query.This distinction is important for statically typed languages where dictionaries/records with a single key can be code-generated differently from regular dictionaries.
Shortcut properties
This PR introduces a new
@shortcut_property
jsdoc tag: it indicates that a property of a class can be used as a shortcut. This is used for many field query types that have single required field, such as term query:{"term": {"some_field": {"value": "some_text"}}}
can also be written as{"term": {"some_field": "some_text"}}
. The class is then defined as follows:Defining the shortcut in the class definition rather than on fields using it is consistent with the implementation in the ES code base: shortcut notations are implemented in the JSON deserialization of classes and not at the class usage location.
The TypeScript generator has been updated to expand shortcut properties as union types at the usage location.
Misc
This PR also adds a number of
@server_default
,@obsolete
and@since
annotations and adds or updates a few common types.