Skip to content

Commit 83afb9b

Browse files
authored
Correct formatting for retrieve specific fields (#9057)
Signed-off-by: Fanit Kolchina <[email protected]>
1 parent 20047e6 commit 83afb9b

File tree

1 file changed

+41
-35
lines changed

1 file changed

+41
-35
lines changed

_search-plugins/searching-data/retrieve-specific-fields.md

Lines changed: 41 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ If `_source` is disabled in the index mappings, [searching with docvalue fields]
6868
You can list the fields you want to retrieve in the `fields` parameter. Wildcard patterns are also accepted:
6969

7070
```json
71-
GET "/index1/_search?pretty"
71+
GET /index1/_search
7272
{
7373
"_source": false,
7474
"fields": ["age", "nam*"],
@@ -169,7 +169,7 @@ The following example demonstrates how to use the `docvalue_fields` parameter.
169169
1. Create an index with the following mappings:
170170

171171
```json
172-
PUT my_index
172+
PUT /my_index
173173
{
174174
"mappings": {
175175
"properties": {
@@ -186,15 +186,18 @@ The following example demonstrates how to use the `docvalue_fields` parameter.
186186
2. Index the following documents into the newly created index:
187187

188188
```json
189-
POST my_index/_doc/1
189+
POST /my_index/_doc/1
190190
{
191191
"title": "OpenSearch Basics",
192192
"author": "John Doe",
193193
"publication_date": "2021-01-01",
194194
"price": 29.99
195195
}
196+
```
197+
{% include copy-curl.html %}
196198

197-
POST my_index/_doc/2
199+
```json
200+
POST /my_index/_doc/2
198201
{
199202
"title": "Advanced OpenSearch",
200203
"author": "Jane Smith",
@@ -207,7 +210,7 @@ The following example demonstrates how to use the `docvalue_fields` parameter.
207210
3. Retrieve only the `author` and `publication_date` fields using `docvalue_fields`:
208211

209212
```json
210-
POST my_index/_search
213+
POST /my_index/_search
211214
{
212215
"_source": false,
213216
"docvalue_fields": ["author", "publication_date"],
@@ -259,7 +262,7 @@ In OpenSearch, if you want to retrieve doc values for nested objects, you cannot
259262
1. Define the index mappings:
260263

261264
```json
262-
PUT my_index
265+
PUT /my_index
263266
{
264267
"mappings": {
265268
"properties": {
@@ -282,7 +285,7 @@ In OpenSearch, if you want to retrieve doc values for nested objects, you cannot
282285
2. Index your data:
283286

284287
```json
285-
POST my_index/_doc/1
288+
POST /my_index/_doc/1
286289
{
287290
"title": "OpenSearch Basics",
288291
"author": "John Doe",
@@ -305,7 +308,7 @@ In OpenSearch, if you want to retrieve doc values for nested objects, you cannot
305308
3. Perform a search with `inner_hits` and `docvalue_fields`:
306309

307310
```json
308-
POST my_index/_search
311+
POST /my_index/_search
309312
{
310313
"query": {
311314
"nested": {
@@ -405,7 +408,7 @@ Unlike `_source`, `stored_fields` must be explicitly defined in the mappings for
405408
1. Create an index with the following mappings:
406409

407410
```json
408-
PUT my_index
411+
PUT /my_index
409412
{
410413
"mappings": {
411414
"properties": {
@@ -432,14 +435,17 @@ Unlike `_source`, `stored_fields` must be explicitly defined in the mappings for
432435
2. Index your data:
433436

434437
```json
435-
POST my_index/_doc/1
438+
POST /my_index/_doc/1
436439
{
437440
"title": "OpenSearch Basics",
438441
"author": "John Doe",
439442
"publication_date": "2022-01-01",
440443
"price": 29.99
441444
}
445+
```
446+
{% include copy-curl.html %}
442447

448+
```json
443449
POST my_index/_doc/2
444450
{
445451
"title": "Advanced OpenSearch",
@@ -453,7 +459,7 @@ Unlike `_source`, `stored_fields` must be explicitly defined in the mappings for
453459
3. Perform a search with `stored_fields`:
454460

455461
```json
456-
POST my_index/_search
462+
POST /my_index/_search
457463
{
458464
"_source": false,
459465
"stored_fields": ["title", "author"],
@@ -508,7 +514,7 @@ In OpenSearch, if you want to retrieve `stored_fields` for nested objects, you c
508514
1. Create an index with the following mappings:
509515

510516
```json
511-
PUT my_index
517+
PUT /my_index
512518
{
513519
"mappings": {
514520
"properties": {
@@ -531,7 +537,7 @@ In OpenSearch, if you want to retrieve `stored_fields` for nested objects, you c
531537
2. Index your data:
532538

533539
```json
534-
POST my_index/_doc/1
540+
POST /my_index/_doc/1
535541
{
536542
"title": "OpenSearch Basics",
537543
"author": "John Doe",
@@ -554,7 +560,7 @@ In OpenSearch, if you want to retrieve `stored_fields` for nested objects, you c
554560
3. Perform a search with `inner_hits` and `stored_fields`:
555561

556562
```json
557-
POST my_index/_search
563+
POST /my_index/_search
558564
{
559565
"_source": false,
560566
"query": {
@@ -641,7 +647,7 @@ You can include or exclude specific fields from the `_source` field in the searc
641647
1. Index your data:
642648

643649
```json
644-
PUT my_index/_doc/1
650+
PUT /my_index/_doc/1
645651
{
646652
"title": "OpenSearch Basics",
647653
"author": "John Doe",
@@ -654,7 +660,7 @@ You can include or exclude specific fields from the `_source` field in the searc
654660
2. Perform a search using source filtering:
655661

656662
```json
657-
POST my_index/_search
663+
POST /my_index/_search
658664
{
659665
"_source": ["title", "author"],
660666
"query": {
@@ -694,7 +700,7 @@ The following is the expected response:
694700
You can choose to exclude fields by using the `"excludes"` parameter in a search request, as shown in the following example:
695701

696702
```json
697-
POST my_index/_search
703+
POST /my_index/_search
698704
{
699705
"_source": {
700706
"excludes": ["price"]
@@ -854,26 +860,26 @@ If you have an index of products, where each product document contains the `pric
854860

855861
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:
856862

857-
```json
858-
GET /products/_search
859-
{
860-
"_source": ["product_id", "name", "price", "discount_percentage"],
861-
"query": {
862-
"match": {
863-
"category": "Electronics"
864-
}
865-
},
866-
"script_fields": {
867-
"discounted_price": {
868-
"script": {
869-
"lang": "painless",
870-
"source": "doc[\"price\"].value * (1 - doc[\"discount_percentage\"].value / 100)"
863+
```json
864+
GET /products/_search
865+
{
866+
"_source": ["product_id", "name", "price", "discount_percentage"],
867+
"query": {
868+
"match": {
869+
"category": "Electronics"
870+
}
871+
},
872+
"script_fields": {
873+
"discounted_price": {
874+
"script": {
875+
"lang": "painless",
876+
"source": "doc[\"price\"].value * (1 - doc[\"discount_percentage\"].value / 100)"
877+
}
878+
}
871879
}
872880
}
873-
}
874-
}
875-
```
876-
{% include copy-curl.html %}
881+
```
882+
{% include copy-curl.html %}
877883

878884
You should receive the following response:
879885

0 commit comments

Comments
 (0)