Skip to content

Commit

Permalink
Merge branch 'main' into workspace_privacy
Browse files Browse the repository at this point in the history
  • Loading branch information
Naarcha-AWS authored Jan 13, 2025
2 parents de5ed8b + f87790d commit f8d14e7
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 38 deletions.
2 changes: 2 additions & 0 deletions _getting-started/search-data.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
76 changes: 41 additions & 35 deletions _search-plugins/searching-data/retrieve-specific-fields.md
Original file line number Diff line number Diff line change
Expand Up @@ -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*"],
Expand Down Expand Up @@ -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": {
Expand All @@ -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",
Expand All @@ -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"],
Expand Down Expand Up @@ -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": {
Expand All @@ -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",
Expand All @@ -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": {
Expand Down Expand Up @@ -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": {
Expand All @@ -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",
Expand All @@ -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"],
Expand Down Expand Up @@ -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": {
Expand All @@ -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",
Expand All @@ -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": {
Expand Down Expand Up @@ -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",
Expand All @@ -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": {
Expand Down Expand Up @@ -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"]
Expand Down Expand Up @@ -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:

Expand Down
6 changes: 3 additions & 3 deletions templates/API_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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:

Expand All @@ -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:

Expand Down

0 comments on commit f8d14e7

Please sign in to comment.