You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Aug 16, 2022. It is now read-only.
Copy file name to clipboardExpand all lines: docs/knn/index.md
+5-5Lines changed: 5 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -13,7 +13,7 @@ Short for its associated *k-nearest neighbors* algorithm, the KNN plugin lets yo
13
13
14
14
## Get started
15
15
16
-
To use the KNN query type, you must create an index with the `index.knn` setting and add one or more fields of the `knn_vector` data type. Additionally, you can specify the `index.knn.space_type` with `l2` or `cosinesimil` to use, respectively, either Euclidean distance or cosine similarity for calculations. By default, `index.knn.space_type` is `l2`. Here is an example that creates an index with two knn_vector fields and uses cosine similarity:
16
+
To use the KNN query type, you must create an index with `index.knn: true`and add one or more fields of the `knn_vector` data type. Additionally, you can specify the `index.knn.space_type`parameter with `l2` or `cosinesimil` to use, respectively, either Euclidean distance or cosine similarity for calculations. By default, `index.knn.space_type` is `l2`. Here is an example that creates an index with two `knn_vector` fields and uses cosine similarity:
17
17
18
18
```json
19
19
PUT my-knn-index-1
@@ -89,9 +89,9 @@ GET my-knn-index-1/_search
89
89
In this case, `k` is the number of neighbors you want the query to return, but you must also include the `size` option. Otherwise, you get `k` results for each shard (and each segment) rather than `k` results for the entire query. The plugin supports a maximum `k` value of 10,000.
90
90
91
91
92
-
## Mixing queries
92
+
## Compound queries with KNN
93
93
94
-
If you use the `knn` query alongside filters, you might receive fewer than `k` results. In this example, `post_filter` reduces the number of results from 2 to 1:
94
+
If you use the `knn` query alongside filters or other clauses (e.g. `bool`, `must`, `match`), you might receive fewer than `k` results. In this example, `post_filter` reduces the number of results from 2 to 1:
95
95
96
96
```json
97
97
GET my-knn-index-1/_search
@@ -143,7 +143,7 @@ PUT my-knn-index-2
143
143
}
144
144
```
145
145
146
-
If you *only* want to use KNN's custom scoring, you can omit `"index.knn": true`, but you lose the ability to perform standard KNN queries on the index. The benefit of this approach is faster indexing speed and lower memory usage.
146
+
If you *only* want to use KNN's custom scoring, you can omit `"index.knn": true`. The benefit of this approach is faster indexing speed and lower memory usage, but you lose the ability to perform standard KNN queries on the index.
147
147
{: .tip}
148
148
149
149
Then add some documents:
@@ -196,7 +196,7 @@ GET my-knn-index-2/_search
196
196
}
197
197
```
198
198
199
-
All options are required.
199
+
All parameters are required.
200
200
201
201
-`lang` is the script type. This value is usually `painless`, but here you must specify `knn`.
202
202
-`source` is the name of the stored script, `knn_store`.
0 commit comments