Skip to content

Commit 8a89d95

Browse files
authored
Add search fields parameter to support high-level field retrieval. (#60100)
This feature adds a new `fields` parameter to the search request, which consults both the document `_source` and the mappings to fetch fields in a consistent way. The PR merges the `field-retrieval` feature branch. Addresses #49028 and #55363.
1 parent 700c04d commit 8a89d95

File tree

117 files changed

+3219
-388
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

117 files changed

+3219
-388
lines changed

docs/build.gradle

+11-6
Original file line numberDiff line numberDiff line change
@@ -144,23 +144,28 @@ Closure setupTwitter = { String name, int count ->
144144
type: date
145145
likes:
146146
type: long
147+
location:
148+
properties:
149+
city:
150+
type: keyword
151+
country:
152+
type: keyword
147153
- do:
148154
bulk:
149155
index: twitter
150156
refresh: true
151157
body: |'''
152158
for (int i = 0; i < count; i++) {
153-
String user, text
159+
String body
154160
if (i == 0) {
155-
user = 'kimchy'
156-
text = 'trying out Elasticsearch'
161+
body = """{"user": "kimchy", "message": "trying out Elasticsearch", "date": "2009-11-15T14:12:12", "likes": 0,
162+
"location": { "city": "Amsterdam", "country": "Netherlands" }}"""
157163
} else {
158-
user = 'test'
159-
text = "some message with the number $i"
164+
body = """{"user": "test", "message": "some message with the number $i", "date": "2009-11-15T14:12:12", "likes": $i}"""
160165
}
161166
buildRestTests.setups[name] += """
162167
{"index":{"_id": "$i"}}
163-
{"user": "$user", "message": "$text", "date": "2009-11-15T14:12:12", "likes": $i}"""
168+
$body"""
164169
}
165170
}
166171
setupTwitter('twitter', 5)

docs/reference/aggregations/misc.asciidoc

+9-9
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,8 @@ GET /twitter/_search?typed_keys
105105
"aggregations": {
106106
"top_users": {
107107
"top_hits": {
108-
"size": 1
108+
"size": 1,
109+
"_source": ["user", "likes", "message"]
109110
}
110111
}
111112
}
@@ -133,17 +134,16 @@ In the response, the aggregations names will be changed to respectively `date_hi
133134
"total": {
134135
"value": 5,
135136
"relation": "eq"
136-
},
137+
},
137138
"max_score": 1.0,
138139
"hits": [
139140
{
140141
"_index": "twitter",
141142
"_id": "0",
142143
"_score": 1.0,
143144
"_source": {
144-
"date": "2009-11-15T14:12:12",
145-
"message": "trying out Elasticsearch",
146145
"user": "kimchy",
146+
"message": "trying out Elasticsearch",
147147
"likes": 0
148148
}
149149
}
@@ -167,12 +167,12 @@ request. This is the case for Terms, Significant Terms and Percentiles aggregati
167167
also contains information about the type of the targeted field: `lterms` (for a terms aggregation on a Long field),
168168
`sigsterms` (for a significant terms aggregation on a String field), `tdigest_percentiles` (for a percentile
169169
aggregation based on the TDigest algorithm).
170-
170+
171171

172172
[[indexing-aggregation-results]]
173173
== Indexing aggregation results with {transforms}
174-
175-
<<transforms,{transforms-cap}>> enable you to convert existing {es} indices
176-
into summarized indices, which provide opportunities for new insights and
177-
analytics. You can use {transforms} to persistently index your aggregation
174+
175+
<<transforms,{transforms-cap}>> enable you to convert existing {es} indices
176+
into summarized indices, which provide opportunities for new insights and
177+
analytics. You can use {transforms} to persistently index your aggregation
178178
results into entity-centric indices.

docs/reference/docs/get.asciidoc

+5-1
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,11 @@ The API returns the following result:
241241
"user": "kimchy",
242242
"date": "2009-11-15T14:12:12",
243243
"likes": 0,
244-
"message": "trying out Elasticsearch"
244+
"message": "trying out Elasticsearch",
245+
"location": {
246+
"city": "Amsterdam",
247+
"country": "Netherlands"
248+
}
245249
}
246250
}
247251
--------------------------------------------------

docs/reference/mapping/types.asciidoc

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ string:: <<text,`text`>>, <<keyword,`keyword`>> and <<wildcard,`wildcard
2222
<<nested>>:: `nested` for arrays of JSON objects
2323

2424
[discrete]
25+
[[spatial_datatypes]]
2526
=== Spatial data types
2627

2728
<<geo-point>>:: `geo_point` for lat/lon points

docs/reference/modules/cross-cluster-search.asciidoc

+4-6
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ GET /cluster_one:twitter/_search
7676
"match": {
7777
"user": "kimchy"
7878
}
79-
}
79+
},
80+
"_source": ["user", "message", "likes"]
8081
}
8182
--------------------------------------------------
8283
// TEST[continued]
@@ -113,7 +114,6 @@ The API returns the following response:
113114
"_score": 1,
114115
"_source": {
115116
"user": "kimchy",
116-
"date": "2009-11-15T14:12:12",
117117
"message": "trying out Elasticsearch",
118118
"likes": 0
119119
}
@@ -147,7 +147,8 @@ GET /twitter,cluster_one:twitter,cluster_two:twitter/_search
147147
"match": {
148148
"user": "kimchy"
149149
}
150-
}
150+
},
151+
"_source": ["user", "message", "likes"]
151152
}
152153
--------------------------------------------------
153154
// TEST[continued]
@@ -184,7 +185,6 @@ The API returns the following response:
184185
"_score": 2,
185186
"_source": {
186187
"user": "kimchy",
187-
"date": "2009-11-15T14:12:12",
188188
"message": "trying out Elasticsearch",
189189
"likes": 0
190190
}
@@ -195,7 +195,6 @@ The API returns the following response:
195195
"_score": 1,
196196
"_source": {
197197
"user": "kimchy",
198-
"date": "2009-11-15T14:12:12",
199198
"message": "trying out Elasticsearch",
200199
"likes": 0
201200
}
@@ -206,7 +205,6 @@ The API returns the following response:
206205
"_score": 1,
207206
"_source": {
208207
"user": "kimchy",
209-
"date": "2009-11-15T14:12:12",
210208
"message": "trying out Elasticsearch",
211209
"likes": 0
212210
}

0 commit comments

Comments
 (0)