Skip to content

Commit c0ceb2a

Browse files
ajleong623kolchfa-awsnatebower
authored andcommitted
Updating the index-parameter page (opensearch-project#10512)
* Update index-parameter.md Signed-off-by: Anthony Leong <[email protected]> * Update index-parameter.md Signed-off-by: Anthony Leong <[email protected]> * Extended description of index and doc values and added table. Signed-off-by: Anthony Leong <[email protected]> * add link to table Signed-off-by: Anthony Leong <[email protected]> * fix invalid link Signed-off-by: Anthony Leong <[email protected]> * Update doc-values.md Signed-off-by: Anthony Leong <[email protected]> * Update doc-values.md Signed-off-by: Anthony Leong <[email protected]> * Apply suggestions from code review Co-authored-by: kolchfa-aws <[email protected]> Signed-off-by: Anthony Leong <[email protected]> * apply asterisks. Signed-off-by: Anthony Leong <[email protected]> * update dead link Signed-off-by: Anthony Leong <[email protected]> * Update _field-types/mapping-parameters/doc-values.md Signed-off-by: kolchfa-aws <[email protected]> * Apply suggestions from code review Signed-off-by: Nathan Bower <[email protected]> --------- Signed-off-by: Anthony Leong <[email protected]> Signed-off-by: kolchfa-aws <[email protected]> Signed-off-by: Nathan Bower <[email protected]> Co-authored-by: kolchfa-aws <[email protected]> Co-authored-by: Nathan Bower <[email protected]>
1 parent dd87f1c commit c0ceb2a

File tree

2 files changed

+79
-8
lines changed

2 files changed

+79
-8
lines changed

_field-types/mapping-parameters/doc-values.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ Option | Description
2121

2222
The `doc_values` parameter is not supported for use in text fields.
2323

24+
For more information on using `doc_values` with the `index` parameter, see [The `index` and `doc_values` parameters compared]({{site.url}}{{site.baseurl}}/field-types/mapping-parameters/index-parameter/#the-index-and-doc-values-parameters-compared).
25+
2426
---
2527

2628
## Example: Creating an index with `doc_values` enabled and disabled

_field-types/mapping-parameters/index-parameter.md

Lines changed: 77 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,25 @@ has_toc: false
1010

1111
# Index
1212

13-
The `index` mapping parameter controls whether a field is searchable by including it in the inverted index. When set to `true`, the field is indexed and available for queries. When set to `false`, the field is stored in the document but not indexed, making it non-searchable. If you do not need to search a particular field, disabling indexing for that field can reduce index size and improve indexing performance. For example, you can disable indexing on large text fields or metadata that is only used for display.
13+
The `index` mapping parameter controls whether a field is included in the inverted index. When set to `true`, the field is indexed and available for queries. When set to `false`, the field is stored in the document but not indexed, making it non-searchable when [`doc_values`]({{site.url}}{{site.baseurl}}/field-types/mapping-parameters/doc-values/) are not enabled. If you do not need to search a particular field, disabling indexing and `doc_values` for that field can reduce index size and improve indexing performance. For example, you can disable indexing on large text fields or metadata that is only used for display.
1414

1515
By default, all field types are indexed.
1616

17+
## The index and doc values parameters compared
18+
19+
When you enable the `index` parameter, OpenSearch creates a mapping of terms to the documents that contain them. For each new document, the values of the indexed fields are broken into terms, and each term is linked to the document ID in the mapping.
20+
21+
When you enable the `doc_values` parameter, OpenSearch creates a reverse mapping: each document is linked to the list of terms found in that field. This is useful for operations like sorting, where the system needs fast access to a document's field values.
22+
23+
The following table illustrates the field behavior depending on the combination of `index` and `doc_values`.
24+
25+
| `index` parameter value | `doc_values` parameter value | Behavior | Use case
26+
| :-- | :-- | :-- | :-- |
27+
| `true` | `true` | The field is searchable and supports sorting, scripting, and aggregations. | Use for any field you want to query directly and perform complex operations on. |
28+
| `true` | `false` | The field is searchable but does not support document-to-term lookup (thus, sorting, scripting, and aggregations take longer). | Use for fields you want to query but don't need for sorting or aggregations, such as `text` fields. |
29+
| `false` | `true` | The field is searchable (although not as efficiently) and supports sorting, scripting, and aggregations. Note that not all field types support `doc_values` (for example, `text` fields do not support `doc_values`). | Use for fields that you want to aggregate on but not filter or query. |
30+
| `false` | `false` | The field is not searchable. Queries that attempt to search the field return an error. | Use for fields on which you do not want to perform any operations, such as metadata fields. |
31+
1732
## Supported data types
1833

1934
The `index` mapping parameter can be applied to the following data types:
@@ -27,7 +42,7 @@ The `index` mapping parameter can be applied to the following data types:
2742

2843
## Enabling indexing on a field
2944

30-
The following request creates an index named `products` with a `description` field that is indexed (the default behavior):
45+
The following request creates an index named `products` with `description` and `name` fields that are indexed (the default behavior):
3146

3247
```json
3348
PUT /products
@@ -36,6 +51,9 @@ PUT /products
3651
"properties": {
3752
"description": {
3853
"type": "text"
54+
},
55+
"name": {
56+
"type": "keyword"
3957
}
4058
}
4159
}
@@ -48,7 +66,8 @@ Index a document using the following request:
4866
```json
4967
PUT /products/_doc/1
5068
{
51-
"description": "This product has a searchable description."
69+
"description": "This product has a searchable description.",
70+
"name": "doc1"
5271
}
5372
```
5473
{% include copy-curl.html %}
@@ -77,14 +96,15 @@ The following response confirms that the indexed document was successfully match
7796
"value": 1,
7897
"relation": "eq"
7998
},
80-
"max_score": 0.2876821,
99+
"max_score": 0.13076457,
81100
"hits": [
82101
{
83102
"_index": "products",
84103
"_id": "1",
85-
"_score": 0.2876821,
104+
"_score": 0.13076457,
86105
"_source": {
87-
"description": "This product has a searchable description."
106+
"description": "This product has a searchable description.",
107+
"name": "doc1"
88108
}
89109
}
90110
]
@@ -94,7 +114,7 @@ The following response confirms that the indexed document was successfully match
94114

95115
## Disabling indexing on a field
96116

97-
Create an index named `products-no-index` with a `description` field that is not indexed:
117+
Create an index named `products-no-index` with a `description` field and a `name` field that are not indexed:
98118

99119
```json
100120
PUT /products-no-index
@@ -104,6 +124,10 @@ PUT /products-no-index
104124
"description": {
105125
"type": "text",
106126
"index": false
127+
},
128+
"name": {
129+
"type": "keyword",
130+
"index": false
107131
}
108132
}
109133
}
@@ -116,7 +140,8 @@ Index a document using the following request:
116140
```json
117141
PUT /products-no-index/_doc/1
118142
{
119-
"description": "This product has a non-searchable description."
143+
"description": "This product has a non-searchable description.",
144+
"name": "doc1"
120145
}
121146
```
122147
{% include copy-curl.html %}
@@ -173,3 +198,47 @@ The following error response indicates that the search query failed because the
173198
"status": 400
174199
}
175200
```
201+
202+
For `text` fields, setting the `index` parameter to `false` disables search on the field because `text` fields do not support `doc_values`. To make other fields not searchable, you must additionally set `doc_values` to `false`.
203+
204+
Query `products-no-index` using the `name` field:
205+
206+
```json
207+
POST /products-no-index/_search
208+
{
209+
"query": {
210+
"term": {
211+
"name": {
212+
"value": "doc1"
213+
}
214+
}
215+
}
216+
}
217+
```
218+
{% include copy-curl.html %}
219+
220+
The following response confirms that the search query succeeded because the `name` field, though not indexed, has `doc_values` enabled:
221+
222+
```json
223+
{
224+
...
225+
"hits": {
226+
"total": {
227+
"value": 1,
228+
"relation": "eq"
229+
},
230+
"max_score": 1.0,
231+
"hits": [
232+
{
233+
"_index": "products-no-index",
234+
"_id": "1",
235+
"_score": 1.0,
236+
"_source": {
237+
"description": "This product has a non-searchable description.",
238+
"name": "doc1"
239+
}
240+
}
241+
]
242+
}
243+
}
244+
```

0 commit comments

Comments
 (0)