Skip to content

Conversation

@carlosdelest
Copy link
Member

Original PR carlosdelest#2
Continued work from kderusso#4

JSON Schema can be stored as part of the template for a Search Application:

PUT _application/search_application/<name>

{ "indices": ["test1"], "template": { "script": { "source": { "query": { "term": { "${field_name}": "${field_value}" } } }, "params": { "field_name": "hello", "field_value": "world" } }, "dictionary": { "properties": { "field_name": { "type": "string" }, "field_value": { "type": "string" } }, "required": ["field_name"], "additionalProperties": false } } } 

dictionary is a JSON Schema used to validate parameters in the _search endpoint in the future.

The dictionary content must be a valid JSON Schema.

Demo script:

# Create indices PUT /test1 PUT /test2 # Add docs POST /test1/_doc/1 { "test": "value", "hello": "world", "value": 1 } POST /test2/_doc/2 { "test": "another", "hello": "world", "value": 2 } # Create search app PUT _application/search_application/test-app { "indices": [ "test1", "test2" ], "template": { "script": { "source": { "query": { "term": { "{{field_name}}": "{{field_value}}" } } }, "params": { "field_name": "hello", "field_value": "world" } }, "dictionary": { "properties": { "field_name": { "type": "string" }, "field_value": { "type": "string" } }, "required": ["field_name"], "additionalProperties": false } } } GET _application/search_application/test-app POST /_application/search_application/test-app/_search { "params": { "field_name": "hello", "field_value": "world" } } } POST /_application/search_application/test-app/_search { "params": { "field_name": "test", "field_value": "another" } } } 
ioanatia and others added 30 commits April 4, 2023 15:04
@elasticsearchmachine elasticsearchmachine added needs:triage Requires assignment of a team area label v8.9.0 external-contributor Pull request authored by a developer outside the Elasticsearch team labels Apr 28, 2023
@carlosdelest carlosdelest added Team:Enterprise Search Meta label for Enterprise Search team and removed external-contributor Pull request authored by a developer outside the Elasticsearch team labels Apr 28, 2023
@elasticsearchmachine elasticsearchmachine removed the needs:triage Requires assignment of a team area label label Apr 28, 2023
api project(':modules:lang-mustache')

// JSON Schema dependencies
implementation "org.apache.commons:commons-lang3:${versions.commons_lang3}"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added dependencies, which were OK according to core-infra team (Slack conversation)

params:
field_name: field1
field_value: value1
dictionary:
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dictionary now allows the full JSON Schema syntax, including required parameters and limiting additionalProperties.

I think we should change the name from dictionary to param_schema. It is more descriptive and in line with using a JSON schema for validation.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like your rename suggestion 👍

}

addQaCheckDependencies(project)
tasks.named("dependencyLicenses").configure {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Licenses for external dependencies needed to be added and some tweaking done to avoid repeating licenses for Jackson.

Some ignored classes to be added to audit as well, already done in other ES modules.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Licenses were duplicated where possible from the codebase, or retrieved in the case of json-schema-validator to ensure the license check is passed.

Copy link
Member

@kderusso kderusso left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great @carlosdelest , thank you! I have a few comments and questions mostly surrounding tests. Great work 💯

params:
field_name: field1
field_value: value1
dictionary:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like your rename suggestion 👍

name: my-test-analytics-collection
ignore: 404

- do:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for taking care of this!

Comment on lines +40 to +41
public SearchSourceBuilder renderQuery(SearchApplication searchApplication, Map<String, Object> templateParams) throws IOException,
ValidationException {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick:

Suggested change
public SearchSourceBuilder renderQuery(SearchApplication searchApplication, Map<String, Object> templateParams) throws IOException,
ValidationException {
public SearchSourceBuilder renderQuery(SearchApplication searchApplication, Map<String, Object> templateParams)
throws IOException, ValidationException {
# Conflicts: #	x-pack/plugin/ent-search/qa/rest/src/yamlRestTest/resources/rest-api-spec/test/entsearch/60_behavioral_analytics_list.yml
@kderusso kderusso added the :EnterpriseSearch/Application Enterprise Search label Apr 28, 2023
@elasticsearchmachine
Copy link
Collaborator

Hi @carlosdelest, I've created a changelog YAML for you.

@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/enterprise-search (Team:Enterprise Search)

Copy link
Member

@kderusso kderusso left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work @carlosdelest 🙌

@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/ent-search-eng (Team:Enterprise Search)

@carlosdelest
Copy link
Member Author

@jimczi , @ioanatia , could I have your review on this? Are we OK with merging this PR and discuss applying the dictionary to default template params as a separate issue?

Copy link
Contributor

@jimczi jimczi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM to unblock

…ms-schema-validation # Conflicts: #	x-pack/plugin/ent-search/build.gradle
@carlosdelest carlosdelest merged commit 1c053b2 into elastic:main May 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

>enhancement :EnterpriseSearch/Application Enterprise Search Team:Enterprise Search Meta label for Enterprise Search team v8.9.0

5 participants