Skip to content

Commit 2be7142

Browse files
committed
docs
1 parent 8ee737d commit 2be7142

File tree

3 files changed

+50
-51
lines changed

3 files changed

+50
-51
lines changed

docs/reference/elasticsearch/mapping-reference/keyword.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,42 @@ Will become:
232232
}
233233
```
234234

235+
If `null_value` is configured, `null` values are replaced with the `null_value` in synthetic source:
236+
237+
$$$synthetic-source-keyword-example-null-value$$$
238+
239+
```console
240+
PUT idx
241+
{
242+
"settings": {
243+
"index": {
244+
"mapping": {
245+
"source": {
246+
"mode": "synthetic"
247+
}
248+
}
249+
}
250+
},
251+
"mappings": {
252+
"properties": {
253+
"kwd": { "type": "keyword", "null_value": "NA" }
254+
}
255+
}
256+
}
257+
PUT idx/_doc/1
258+
{
259+
"kwd": ["foo", null, "bar"]
260+
}
261+
```
262+
263+
Will become:
264+
265+
```console-result
266+
{
267+
"kwd": ["bar", "foo", "NA"]
268+
}
269+
```
270+
235271

236272
## Constant keyword field type [constant-keyword-field-type]
237273

docs/reference/elasticsearch/mapping-reference/text.md

Lines changed: 13 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -104,11 +104,20 @@ Synthetic `_source` is Generally Available only for TSDB indices (indices that h
104104
::::
105105

106106

107-
`text` fields support [synthetic `_source`](/reference/elasticsearch/mapping-reference/mapping-source-field.md#synthetic-source) if they have a [`keyword`](/reference/elasticsearch/mapping-reference/keyword.md#keyword-synthetic-source) sub-field that supports synthetic `_source` or if the `text` field sets `store` to `true`. Either way, it may not have [`copy_to`](/reference/elasticsearch/mapping-reference/copy-to.md).
107+
`text` fields may use a [`keyword`](/reference/elasticsearch/mapping-reference/keyword.md#keyword-synthetic-source) sub-field to support [synthetic `_source`](/reference/elasticsearch/mapping-reference/mapping-source-field.md#synthetic-source) without storing values of the text field itself.
108+
109+
::::{note}
110+
Synthetic source of the `text` field will have the same [modifications](/reference/elasticsearch/mapping-reference/mapping-source-field.md#synthetic-source) as a `keyword` field in this case.
111+
112+
These modifications can impact usage of `text` fields:
113+
* Reordering text fields can have an effect on [phrase](/reference/query-languages/query-dsl/query-dsl-match-query-phrase.md) and [span](/reference/query-languages/query-dsl/span-queries.md) queries. See the discussion about [`position_increment_gap`](/reference/elasticsearch/mapping-reference/position-increment-gap.md) for more detail. You can avoid this by making sure the `slop` parameter on the phrase queries is lower than the `position_increment_gap`. This is the default.
114+
* Handling of `null` values is different. `text` fields ignore `null` values but `keyword` fields support replacing `null`s with a value specified in the `null_value` parameter. This replacement will be represented in synthetic source.
115+
::::
108116

109-
If using a sub-`keyword` field, then the values are sorted in the same way as a `keyword` field’s values are sorted. By default, that means sorted with duplicates removed. So:
110117

111-
$$$synthetic-source-text-example-default$$$
118+
If the `text` field sets `store` to `true` then the sub-field is not used and modifications mentioned above do not apply.
119+
120+
$$$synthetic-source-text-example-stored$$$
112121

113122
```console
114123
PUT idx
@@ -126,6 +135,7 @@ PUT idx
126135
"properties": {
127136
"text": {
128137
"type": "text",
138+
"store": true,
129139
"fields": {
130140
"raw": {
131141
"type": "keyword"
@@ -147,54 +157,6 @@ PUT idx/_doc/1
147157

148158
Will become:
149159

150-
```console-result
151-
{
152-
"text": [
153-
"jumped over the lazy dog",
154-
"the quick brown fox"
155-
]
156-
}
157-
```
158-
159-
::::{note}
160-
Reordering text fields can have an effect on [phrase](/reference/query-languages/query-dsl/query-dsl-match-query-phrase.md) and [span](/reference/query-languages/query-dsl/span-queries.md) queries. See the discussion about [`position_increment_gap`](/reference/elasticsearch/mapping-reference/position-increment-gap.md) for more detail. You can avoid this by making sure the `slop` parameter on the phrase queries is lower than the `position_increment_gap`. This is the default.
161-
::::
162-
163-
164-
If the `text` field sets `store` to true then order and duplicates are preserved.
165-
166-
$$$synthetic-source-text-example-stored$$$
167-
168-
```console
169-
PUT idx
170-
{
171-
"settings": {
172-
"index": {
173-
"mapping": {
174-
"source": {
175-
"mode": "synthetic"
176-
}
177-
}
178-
}
179-
},
180-
"mappings": {
181-
"properties": {
182-
"text": { "type": "text", "store": true }
183-
}
184-
}
185-
}
186-
PUT idx/_doc/1
187-
{
188-
"text": [
189-
"the quick brown fox",
190-
"the quick brown fox",
191-
"jumped over the lazy dog"
192-
]
193-
}
194-
```
195-
196-
Will become:
197-
198160
```console-result
199161
{
200162
"text": [

server/src/main/java/org/elasticsearch/index/mapper/TextFieldMapper.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1093,6 +1093,7 @@ private BlockSourceReader.LeafIteratorLookup blockReaderDisiLookup(BlockLoaderCo
10931093
// between text and keyword).
10941094
return BlockSourceReader.lookupMatchingAll();
10951095
}
1096+
10961097
if (isIndexed()) {
10971098
if (getTextSearchInfo().hasNorms()) {
10981099
return BlockSourceReader.lookupFromNorms(name());

0 commit comments

Comments
 (0)