Skip to content

Commit 9c7a5c7

Browse files
authored
[DOCS] Move source filtering examples (#57689) (#57695)
Moves the source filtering example snippets form the "Request body search" API docs page to the "Return fields in a search" section of the "Run a search" page.
1 parent 98c379c commit 9c7a5c7

File tree

4 files changed

+95
-72
lines changed

4 files changed

+95
-72
lines changed

docs/reference/redirects.asciidoc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -896,4 +896,9 @@ For search examples, see <<run-a-search>>.
896896
==== From / size
897897
898898
See <<paginate-search-results>>.
899+
900+
[role="exclude",id="request-body-search-source-filtering"]
901+
==== Source filtering
902+
903+
See <<search-fields>>.
899904
////

docs/reference/search/request/from-size.asciidoc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ GET /_search
2525
"from": 5,
2626
"size": 20,
2727
"query": {
28-
"term": { "user": "kimchy" }
28+
"term": {
29+
"user.id": "8a4f500d"
30+
}
2931
}
3032
}
3133
----
Lines changed: 1 addition & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,71 +1,4 @@
11
[[request-body-search-source-filtering]]
22
==== Source filtering
33

4-
5-
Allows to control how the `_source` field is returned with every hit.
6-
7-
By default operations return the contents of the `_source` field unless
8-
you have used the `stored_fields` parameter or if the `_source` field is disabled.
9-
10-
You can turn off `_source` retrieval by using the `_source` parameter:
11-
12-
To disable `_source` retrieval set to `false`:
13-
14-
[source,console]
15-
--------------------------------------------------
16-
GET /_search
17-
{
18-
"_source": false,
19-
"query" : {
20-
"term" : { "user" : "kimchy" }
21-
}
22-
}
23-
--------------------------------------------------
24-
25-
The `_source` also accepts one or more wildcard patterns to control what parts of the `_source` should be returned:
26-
27-
For example:
28-
29-
[source,console]
30-
--------------------------------------------------
31-
GET /_search
32-
{
33-
"_source": "obj.*",
34-
"query" : {
35-
"term" : { "user" : "kimchy" }
36-
}
37-
}
38-
--------------------------------------------------
39-
40-
Or
41-
42-
[source,console]
43-
--------------------------------------------------
44-
GET /_search
45-
{
46-
"_source": [ "obj1.*", "obj2.*" ],
47-
"query" : {
48-
"term" : { "user" : "kimchy" }
49-
}
50-
}
51-
--------------------------------------------------
52-
53-
Finally, for complete control, you can specify both `includes` and `excludes`
54-
patterns. If `includes` is not empty, then only fields that match one of the
55-
patterns in `includes` but none of the patterns in `excludes` are provided in
56-
`_source`. If `includes` is empty, then all fields are provided in `_source`,
57-
except for those that match a pattern in `excludes`.
58-
59-
[source,console]
60-
--------------------------------------------------
61-
GET /_search
62-
{
63-
"_source": {
64-
"includes": [ "obj1.*", "obj2.*" ],
65-
"excludes": [ "*.description" ]
66-
},
67-
"query" : {
68-
"term" : { "user" : "kimchy" }
69-
}
70-
}
71-
--------------------------------------------------
4+
See <<search-fields>>.

docs/reference/search/search-fields.asciidoc

Lines changed: 86 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,92 @@
55
By default, each hit in the search response includes the document
66
<<mapping-source-field,`_source`>>, which is the entire JSON object that was
77
provided when indexing the document. If you only need certain fields in the
8-
search response, you can use
9-
<<request-body-search-source-filtering,source filtering>> to restrict what
10-
parts of the source are returned.
8+
search response, you can use the
9+
<<request-body-search-source-filtering,`_source`>> parameter to restrict what
10+
parts of the source are returned. This is called _source filtering_.
11+
12+
.*Example*
13+
[%collapsible]
14+
====
15+
The following search API request sets the `_source` request body parameter to
16+
`false`. The document source is not included in the response.
17+
18+
[source,console]
19+
----
20+
GET /_search
21+
{
22+
"_source": false,
23+
"query": {
24+
"term": {
25+
"user.id": "8a4f500d"
26+
}
27+
}
28+
}
29+
----
30+
31+
To return only a subset of source fields, specify a wildcard (`*`) pattern in
32+
the `_source` parameter. The following search API request returns the source for
33+
only the `obj` field and its properties.
34+
35+
[source,console]
36+
----
37+
GET /_search
38+
{
39+
"_source": "obj.*",
40+
"query": {
41+
"term": {
42+
"user.id": "8a4f500d"
43+
}
44+
}
45+
}
46+
----
47+
48+
You can also specify an array of wildcard patterns in the `_source` field. The
49+
following search API request returns the source for only the `obj1` and
50+
`obj2` fields and their properties.
51+
52+
[source,console]
53+
----
54+
GET /_search
55+
{
56+
"_source": [ "obj1.*", "obj2.*" ],
57+
"query": {
58+
"term": {
59+
"user.id": "8a4f500d"
60+
}
61+
}
62+
}
63+
----
64+
65+
For finer control, you can specify an object containing arrays of `includes` and
66+
`excludes` patterns in the `_source` parameter.
67+
68+
If the `includes` property is specified, only source fields that match one of
69+
its patterns are returned. You can exclude fields from this subset using the
70+
`excludes` property.
71+
72+
If the `includes` property is not specified, the entire document source is
73+
returned, excluding any fields that match a pattern in the `excludes` property.
74+
75+
The following search API request returns the source for only the `obj1` and
76+
`obj2` fields and their properties, excluding any child `description` fields.
77+
78+
[source,console]
79+
----
80+
GET /_search
81+
{
82+
"_source": {
83+
"includes": [ "obj1.*", "obj2.*" ],
84+
"excludes": [ "*.description" ]
85+
},
86+
"query": {
87+
"term": {
88+
"user.id": "8a4f500d"
89+
}
90+
}
91+
}
92+
----
93+
====
1194

1295
Returning fields using only the document source has some limitations:
1396

0 commit comments

Comments
 (0)