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
[DOC-12432] Document Usage of {"ctl": { "validate" : true }, } for Search Queries (#302)
* [DOC-12432] Clarifying search_after and search_before behaviour, along with sorting and general pagination tips.
Adding documentation on the new validate object - in search-request-params and as examples in the simple-search topics.
Adding query results to the example in the REST API topic, and expanding on what those results mean.
Fixing error in field path in the example full-request.
* Add 7.6.5 version labels for validate property
---------
Co-authored-by: Sarah Welton <[email protected]>
Copy file name to clipboardExpand all lines: modules/search/pages/search-request-params.adoc
+50-25Lines changed: 50 additions & 25 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -48,8 +48,13 @@ Set the total number of results to return for a single page of search results.
48
48
49
49
If you provide both the `size` and `limit` properties, the Search Service uses the `size` value.
50
50
51
-
If you do not provide a `from`, `size`, or other pagination settings in your query, the Search Service defaults to a `size` value of `10` and a `from` value of `0`.
52
-
This means the Search Service does not offset results, and returns the first `10` matches to your query.
51
+
The Search Service returns the `size` number of results:
52
+
53
+
* Starting at the offset in the `from` or `offset` property.
54
+
* Starting from the key specified in the <<search_after,search_after property>>.
55
+
* Starting backward from the key specified in the <<search_before,search_before property>>.
56
+
57
+
The `size` property is added by default to all Search requests, if not otherwise specified, with a value of `10`.
53
58
54
59
|from/offset |Integer |No a|
55
60
@@ -59,8 +64,7 @@ For example, if you set a `size` value of `5` and a `from` value of `10`, the Se
59
64
60
65
If you provide both the `from` and `offset` properties, the Search Service uses the `from` value.
61
66
62
-
If you do not provide a `from`, `size`, or other pagination settings in your query, the Search Service defaults to a `size` value of `10` and a `from` value of `0`.
63
-
This means the Search Service does not offset results, and returns the first `10` matches to your query.
67
+
The `from` property is added by default to all Search requests, if not otherwise specified, with a value of `0`.
64
68
65
69
|highlight |Object |No a|
66
70
@@ -92,7 +96,7 @@ To create an explanation for a search result's score in search results, set `exp
92
96
93
97
To turn off explanations for search result scoring, set `explain` to `false`.
94
98
95
-
|[[sort-array]]sort |Array |No a|
99
+
|[[sort_arr]]sort |Array |No a|
96
100
97
101
Contains an array of strings or JSON objects to set how to sort search results.
98
102
By default, the Search Service sorts results based on score values, from highest to lowest.
@@ -122,39 +126,45 @@ To turn off document relevancy scoring in search results, set `score` to `none`.
122
126
123
127
To turn on document relevancy scoring in search results, remove the `score` property.
124
128
125
-
|search_after |Array |No a|
129
+
|[[search_after]]search_after |Array |No a|
126
130
127
-
NOTE: If you use `search_after` in a search request, you cannot use `search_before`. Both properties are included in the example code to show the correct syntax.
131
+
NOTE: If you use `search_after` in a search request, you can't use `search_before`.
132
+
Both properties are included in the example code to show the correct syntax.
128
133
129
134
Use `search_after` with `from/offset` and `sort` to control pagination in search results.
130
135
131
-
For example, if you had a set of 10 documents to sort based on `_id` values of 1-10, with `from` set to `2` and `search_after` set to `8`, documents 9-10 appear on the same page.
136
+
Give a value for each string or JSON object in the <<sort_arr,sort array>> to the `search_after` array.
137
+
You must provide the values in the same order that they appear in the <<sort_arr,sort array>>.
138
+
Values in the `search_after` array must be strings.
139
+
You cannot use `search_after` with numbers or other field data types - if your `sort` array includes fields with a `date` or `number` type, you cannot use `search_after`.
140
+
Only result relevancy score values can be entered as strings in the array.
132
141
133
-
You must give a value for each string or JSON object in the `sort` array to the `search_after` array.
134
-
The Search Service starts search result pagination after the document with those values.
142
+
The Search Service starts search result pagination after the document with the values you provide in the array.
135
143
136
-
You must provide the values in the same order that they appear in the `sort` array.
137
-
Your `sort` array must force a total order on your search results.
144
+
For example, if you had a set of 10 documents to sort based on `_id` values of 1-10, with `from` set to `2` and `search_after` set to `8`, documents 9-10 appear on the same page.
138
145
139
-
Use `search_after` to make the memory requirements of deeper page searches more manageable, when compared to using only `from/offset`.
140
-
`search_after`lets you start your search results from a specific result, rather than needing to process a number of search results to skip.
146
+
To reduce the resource costs of deeper pagination on your Search queries, try to always include your document ID values as the final sort criteria in your <<sort_arr,sort array>>.
147
+
Set the `search_after`property to include the values from the last result on your previous page of search results to effectively paginate.
141
148
142
-
|search_before |Array |No a|
149
+
|[[search_before]]search_before |Array |No a|
143
150
144
-
NOTE: If you use `search_before` in a search request, you cannot use `search_after`. Both properties are included in the example code to show the correct syntax.
151
+
NOTE: If you use `search_before` in a search request, you can't use `search_after`.
152
+
Both properties are included in the example code to show the correct syntax.
145
153
146
154
Use `search_before` with `from/offset` and `sort` to control pagination in search results.
147
155
148
-
For example, if you had a set of 10 documents to sort based on `_id` values of 1-10, with `from` set to `2` and `search_before` set to `8`, documents 2-6 appear on the same page.
156
+
Give a value for each string or JSON object in the `sort` array to the `search_before` array.
157
+
You must provide the values in the same order that they appear in the `sort` array.
158
+
Values in the `search_before` array must be strings.
159
+
You cannot use `search_before` with numbers or other field data types - if your `sort` array includes fields with a `date` or `number` type, you cannot use `search_before`.
160
+
Only result relevancy score values can be entered as strings in the array.
149
161
150
-
You must give a value for each string or JSON object in the `sort` array to the `search_before` array.
151
-
The Search Service starts search result pagination before the document with those values.
162
+
The Search Service starts search result pagination before the document with the values you provide in the array.
152
163
153
-
You must provide the values in the same order that they appear in the `sort` array.
154
-
Your `sort` array must force a total order on your search results.
164
+
For example, if you had a set of 10 documents to sort based on `_id` values of 1-10, with `from` set to `2` and `search_before` set to `8`, documents 2-6 appear on the same page.
155
165
156
-
Use `search_before` to make the memory requirements of deeper page searches more manageable, when compared to using only `from/offset`.
157
-
`search_before`lets you start your search results back from a specific result, rather than needing to process a number of search results to skip.
166
+
To reduce the resource costs of deeper pagination on your Search queries, try to always include your document ID values as the final sort criteria in your <<sort_arr,sort array>>.
167
+
Set the `search_before`property to include the values from the last result on your previous page of search results to effectively paginate.
158
168
159
169
|[[collections]]collections |Array |No |Contains an array of strings that specify the collections where you want to run the query.
160
170
@@ -1904,7 +1914,9 @@ The Search Service uses a consistency vector to synchronize the last document wr
The `ctl` object contains the following properties:
1917
+
In Couchbase Server 7.6.5 and later, you can also use the `ctl` object with the `validate` property to add an extra check to your queries and get help troubleshooting when a query does not return results.
1918
+
1919
+
The `ctl` object can contain the following properties:
1908
1920
1909
1921
[cols="1,1,1,4"]
1910
1922
|====
@@ -1923,6 +1935,18 @@ An object that contains a `vectors` object and the `level` and `results` propert
1923
1935
1924
1936
For more information, see <<consistency,>>.
1925
1937
1938
+
|[[validate]]validate |Boolean |No a|
1939
+
1940
+
[.status]#Couchbase Server 7.6.5#
1941
+
1942
+
Add the `validate` property with a value of `true` to add extra validation checks to your Search query.
1943
+
1944
+
For example, the Search Service can tell you through the Web Console or the REST API that a field in your Search query is not in your Search index:
1945
+
1946
+
----
1947
+
err: query_validate: field not indexed, field: ratings.Cleanliness, type: number
1948
+
----
1949
+
1926
1950
|====
1927
1951
1928
1952
[#consistency]
@@ -2181,7 +2205,8 @@ The following `sort` object orders search results by the values in `field1`, the
TIP: For the best results with sorting and page navigation in search results, always include your document ID values (`_id` or `-_id`) as the final sort criteria in your `sort` object.
2208
+
This means that if 2 documents have the same value in `field1`, then the Search Service will sort them again based on their `field2` values.
2209
+
If they have the same value in `field2`, then sorting will happen again based on each document's score, and then finally the documents' ID values.
2185
2210
2186
2211
The `sort` object can contain the following string values:
Copy file name to clipboardExpand all lines: modules/search/pages/simple-search-ui.adoc
+19-1Lines changed: 19 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -31,7 +31,7 @@ To run a simple search with the {page-ui-name}:
31
31
. Press kbd:[Enter].
32
32
. (Optional) To view a document and its source collection, click a document name in the search results list.
33
33
34
-
=== Example
34
+
=== Example: Simple Text Search
35
35
36
36
For example, the following query searches for the strings `view`, `food`, and `beach`:
37
37
@@ -45,6 +45,24 @@ It also returns all available fields in the index, and returns 10 results per pa
45
45
46
46
TIP: Use the xref:search-request-params.adoc#collections[`collections` parameter] in your request to specify an array of collections to search from the Search index.
47
47
48
+
=== Example: Validate a Search Query
49
+
50
+
[.status]#Couchbase Server 7.6.5#
51
+
52
+
For example, the following query searches a Search index, `landmark-content-index`, using a xref:search-request-params.adoc#geopoint-queries-distance[Distance/Radius-Based Geopoint Query] on the `geo` field.
53
+
The query includes the xref:search-request-params.adoc#ctl[ctl object] with the `validate` property to validate the query:
54
+
55
+
[source,json]
56
+
----
57
+
include::example$run-search-validate-ui.jsonc[]
58
+
----
59
+
60
+
Since the `landmark-content-index` does not include a mapping for the `geo` field and the `validate` property is included in the query, the Web Console returns the following error:
61
+
62
+
----
63
+
query_validate: field not indexed, name: geo, type: geopoint
64
+
----
65
+
48
66
== Next Steps
49
67
50
68
If you do not get the search results you were expecting, you can change the xref:search-request-params.adoc[JSON payload for your Search query].
0 commit comments