From 20047e69ec2c482b4521d6d1c0918f065b64ea3c Mon Sep 17 00:00:00 2001 From: kolchfa-aws <105444904+kolchfa-aws@users.noreply.github.com> Date: Mon, 13 Jan 2025 14:47:05 -0500 Subject: [PATCH 1/3] Add a clarifying statement to search getting started (#9055) Signed-off-by: Fanit Kolchina --- _getting-started/search-data.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/_getting-started/search-data.md b/_getting-started/search-data.md index 8e4169fbae..1043d60afb 100644 --- a/_getting-started/search-data.md +++ b/_getting-started/search-data.md @@ -14,6 +14,8 @@ In OpenSearch, there are several ways to search data: - [Piped Processing Language (PPL)]({{site.url}}{{site.baseurl}}/search-plugins/sql/ppl/index/): The primary language used for observability in OpenSearch. PPL uses a pipe syntax that chains commands into a query. - [Dashboards Query Language (DQL)]({{site.url}}{{site.baseurl}}/dashboards/dql/): A simple text-based query language for filtering data in OpenSearch Dashboards. +This tutorial contains a brief introduction to searching using [query string queries](#query-string-queries) and [query DSL](#query-dsl). + ## Prepare the data For this tutorial, you'll need to index student data if you haven't done so already. You can start by deleting the `students` index (`DELETE /students`) and then sending the following bulk request: From 83afb9b55edfa06cce0aa02483bd0edc53abb5f4 Mon Sep 17 00:00:00 2001 From: kolchfa-aws <105444904+kolchfa-aws@users.noreply.github.com> Date: Mon, 13 Jan 2025 15:16:13 -0500 Subject: [PATCH 2/3] Correct formatting for retrieve specific fields (#9057) Signed-off-by: Fanit Kolchina --- .../retrieve-specific-fields.md | 76 ++++++++++--------- 1 file changed, 41 insertions(+), 35 deletions(-) diff --git a/_search-plugins/searching-data/retrieve-specific-fields.md b/_search-plugins/searching-data/retrieve-specific-fields.md index ce860470dc..95c72e4788 100644 --- a/_search-plugins/searching-data/retrieve-specific-fields.md +++ b/_search-plugins/searching-data/retrieve-specific-fields.md @@ -68,7 +68,7 @@ If `_source` is disabled in the index mappings, [searching with docvalue fields] You can list the fields you want to retrieve in the `fields` parameter. Wildcard patterns are also accepted: ```json -GET "/index1/_search?pretty" +GET /index1/_search { "_source": false, "fields": ["age", "nam*"], @@ -169,7 +169,7 @@ The following example demonstrates how to use the `docvalue_fields` parameter. 1. Create an index with the following mappings: ```json - PUT my_index + PUT /my_index { "mappings": { "properties": { @@ -186,15 +186,18 @@ The following example demonstrates how to use the `docvalue_fields` parameter. 2. Index the following documents into the newly created index: ```json - POST my_index/_doc/1 + POST /my_index/_doc/1 { "title": "OpenSearch Basics", "author": "John Doe", "publication_date": "2021-01-01", "price": 29.99 } + ``` + {% include copy-curl.html %} - POST my_index/_doc/2 + ```json + POST /my_index/_doc/2 { "title": "Advanced OpenSearch", "author": "Jane Smith", @@ -207,7 +210,7 @@ The following example demonstrates how to use the `docvalue_fields` parameter. 3. Retrieve only the `author` and `publication_date` fields using `docvalue_fields`: ```json - POST my_index/_search + POST /my_index/_search { "_source": false, "docvalue_fields": ["author", "publication_date"], @@ -259,7 +262,7 @@ In OpenSearch, if you want to retrieve doc values for nested objects, you cannot 1. Define the index mappings: ```json - PUT my_index + PUT /my_index { "mappings": { "properties": { @@ -282,7 +285,7 @@ In OpenSearch, if you want to retrieve doc values for nested objects, you cannot 2. Index your data: ```json - POST my_index/_doc/1 + POST /my_index/_doc/1 { "title": "OpenSearch Basics", "author": "John Doe", @@ -305,7 +308,7 @@ In OpenSearch, if you want to retrieve doc values for nested objects, you cannot 3. Perform a search with `inner_hits` and `docvalue_fields`: ```json - POST my_index/_search + POST /my_index/_search { "query": { "nested": { @@ -405,7 +408,7 @@ Unlike `_source`, `stored_fields` must be explicitly defined in the mappings for 1. Create an index with the following mappings: ```json - PUT my_index + PUT /my_index { "mappings": { "properties": { @@ -432,14 +435,17 @@ Unlike `_source`, `stored_fields` must be explicitly defined in the mappings for 2. Index your data: ```json - POST my_index/_doc/1 + POST /my_index/_doc/1 { "title": "OpenSearch Basics", "author": "John Doe", "publication_date": "2022-01-01", "price": 29.99 } + ``` + {% include copy-curl.html %} + ```json POST my_index/_doc/2 { "title": "Advanced OpenSearch", @@ -453,7 +459,7 @@ Unlike `_source`, `stored_fields` must be explicitly defined in the mappings for 3. Perform a search with `stored_fields`: ```json - POST my_index/_search + POST /my_index/_search { "_source": false, "stored_fields": ["title", "author"], @@ -508,7 +514,7 @@ In OpenSearch, if you want to retrieve `stored_fields` for nested objects, you c 1. Create an index with the following mappings: ```json - PUT my_index + PUT /my_index { "mappings": { "properties": { @@ -531,7 +537,7 @@ In OpenSearch, if you want to retrieve `stored_fields` for nested objects, you c 2. Index your data: ```json - POST my_index/_doc/1 + POST /my_index/_doc/1 { "title": "OpenSearch Basics", "author": "John Doe", @@ -554,7 +560,7 @@ In OpenSearch, if you want to retrieve `stored_fields` for nested objects, you c 3. Perform a search with `inner_hits` and `stored_fields`: ```json - POST my_index/_search + POST /my_index/_search { "_source": false, "query": { @@ -641,7 +647,7 @@ You can include or exclude specific fields from the `_source` field in the searc 1. Index your data: ```json - PUT my_index/_doc/1 + PUT /my_index/_doc/1 { "title": "OpenSearch Basics", "author": "John Doe", @@ -654,7 +660,7 @@ You can include or exclude specific fields from the `_source` field in the searc 2. Perform a search using source filtering: ```json - POST my_index/_search + POST /my_index/_search { "_source": ["title", "author"], "query": { @@ -694,7 +700,7 @@ The following is the expected response: You can choose to exclude fields by using the `"excludes"` parameter in a search request, as shown in the following example: ```json -POST my_index/_search +POST /my_index/_search { "_source": { "excludes": ["price"] @@ -854,26 +860,26 @@ If you have an index of products, where each product document contains the `pric 2. Use the `script_fields` parameter to include a custom field called `discounted_price` in the search results. This field will be calculated based on the `price` and `discount_percentage` fields using a script: -```json -GET /products/_search -{ - "_source": ["product_id", "name", "price", "discount_percentage"], - "query": { - "match": { - "category": "Electronics" - } - }, - "script_fields": { - "discounted_price": { - "script": { - "lang": "painless", - "source": "doc[\"price\"].value * (1 - doc[\"discount_percentage\"].value / 100)" + ```json + GET /products/_search + { + "_source": ["product_id", "name", "price", "discount_percentage"], + "query": { + "match": { + "category": "Electronics" + } + }, + "script_fields": { + "discounted_price": { + "script": { + "lang": "painless", + "source": "doc[\"price\"].value * (1 - doc[\"discount_percentage\"].value / 100)" + } + } } } - } -} -``` -{% include copy-curl.html %} + ``` + {% include copy-curl.html %} You should receive the following response: From f87790dd62215e53ef08ea5587791a940196e30a Mon Sep 17 00:00:00 2001 From: kolchfa-aws <105444904+kolchfa-aws@users.noreply.github.com> Date: Mon, 13 Jan 2025 16:21:26 -0500 Subject: [PATCH 3/3] Update API_TEMPLATE.md (#9059) Signed-off-by: kolchfa-aws <105444904+kolchfa-aws@users.noreply.github.com> --- templates/API_TEMPLATE.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/templates/API_TEMPLATE.md b/templates/API_TEMPLATE.md index 654b3c7a6b..736eb74338 100644 --- a/templates/API_TEMPLATE.md +++ b/templates/API_TEMPLATE.md @@ -46,7 +46,7 @@ The following table lists the available request body fields. ## Example request(s) -**TIP:** If multiple examples exist for the request, seperate those examples using an `h3` header underneath this section. +**TIP:** If multiple examples exist for the request, separate those examples using an `h3` header underneath this section. ### Request with an example object @@ -63,7 +63,7 @@ POST /_example/endpoint/ ``` {% include copy-curl.html %} -## Request without an example object +### Request without an example object The following example shows an API request without an example object: @@ -75,7 +75,7 @@ POST /_example/endpoint/ ## Example response -**TIP:** If multiple response examples exist for the request, seperate those examples using an `h3` header underneath this section, similar to the [Example requests](#example-requests). +**TIP:** If multiple examples exist for the request, separate those examples using an `h3` header under this section, similar to the [Example requests](#example-requests). The following example shows an API response: