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
@@ -5,11 +5,57 @@ Search functions enable you to use full text search queries directly within a N1
5
5
== Prerequisites
6
6
7
7
To use any of the search functions, the Search service must be available on the cluster.
8
-
It is also recommended, but not required, that you should create suitable full text indexes for the searches that you need to perform.
8
+
It is required for you to create suitable full text indexes for the searches that you want to perform.
9
9
10
10
[NOTE]
11
11
--
12
-
The examples in this page all assume that demonstration full text indexes have been created.
12
+
The examples in this page assume that you have a full text search index created with this definition, unless specified otherwise ..
13
+
[source,json]
14
+
----
15
+
{
16
+
"name": "travel-sample-inventory-hotels",
17
+
"type": "fulltext-index",
18
+
"params": {
19
+
"doc_config": {
20
+
"mode": "scope.collection.type_field",
21
+
"type_field": "type"
22
+
},
23
+
"mapping": {
24
+
"default_analyzer": "standard",
25
+
"default_datetime_parser": "dateTimeOptional",
26
+
"default_field": "_all",
27
+
"default_mapping": {
28
+
"dynamic": true,
29
+
"enabled": false
30
+
},
31
+
"default_type": "_default",
32
+
"docvalues_dynamic": false,
33
+
"index_dynamic": true,
34
+
"store_dynamic": false,
35
+
"type_field": "_type",
36
+
"types": {
37
+
"inventory.hotel": {
38
+
"dynamic": true,
39
+
"enabled": true
40
+
}
41
+
}
42
+
},
43
+
"store": {
44
+
"indexType": "scorch",
45
+
"segmentVersion": 15
46
+
}
47
+
},
48
+
"sourceType": "gocbcore",
49
+
"sourceName": "travel-sample",
50
+
"sourceUUID": "",
51
+
"sourceParams": {},
52
+
"planParams": {
53
+
"indexPartitions": 1
54
+
},
55
+
"uuid": ""
56
+
}
57
+
----
58
+
13
59
--
14
60
15
61
=== Authorization
@@ -203,33 +249,29 @@ The following queries are equivalent:
203
249
[source,n1ql]
204
250
----
205
251
SELECT META(t1).id
206
-
FROM `travel-sample`.inventory.airline AS t1
252
+
FROM `travel-sample`.inventory.hotel AS t1
207
253
WHERE SEARCH(t1.country, "+United +States");
208
254
----
209
255
210
256
[source,n1ql]
211
257
----
212
258
SELECT META(t1).id
213
-
FROM `travel-sample`.inventory.airline AS t1
259
+
FROM `travel-sample`.inventory.hotel AS t1
214
260
WHERE SEARCH(t1, "country:\"United States\"");
215
261
----
216
262
217
263
.Results
218
264
[source,json]
219
265
----
220
266
[
221
-
222
267
{
223
-
"id": "airline_10"
268
+
"id": "hotel_26215"
224
269
},
225
270
{
226
-
"id": "airline_10123"
271
+
"id": "hotel_7396"
227
272
},
228
273
{
229
-
"id": "airline_10226"
230
-
},
231
-
{
232
-
"id": "airline_10748"
274
+
"id": "hotel_32177"
233
275
},
234
276
...
235
277
]
@@ -350,8 +392,51 @@ WHERE t1.type = "hotel" AND SEARCH(t1.description, "amazing");
350
392
----
351
393
352
394
If the full text search index being queried has its default mapping disabled and has a custom type mapping defined, the query needs to specify the type explicitly.
353
-
354
-
//The above query uses the demonstration index xref:fts:fts-demonstration-indexes.adoc#travel-sample-index-hotel-description[travel-sample-index-hotel-description], which has the custom type mapping "hotel".
395
+
The above query uses the following index definition ..
396
+
[source,json]
397
+
----
398
+
{
399
+
"name": "travel-sample-hotels",
400
+
"type": "fulltext-index",
401
+
"params": {
402
+
"doc_config": {
403
+
"mode": "type_field",
404
+
"type_field": "type"
405
+
},
406
+
"mapping": {
407
+
"default_analyzer": "standard",
408
+
"default_datetime_parser": "dateTimeOptional",
409
+
"default_field": "_all",
410
+
"default_mapping": {
411
+
"dynamic": true,
412
+
"enabled": false
413
+
},
414
+
"default_type": "_default",
415
+
"index_dynamic": true,
416
+
"store_dynamic": true,
417
+
"type_field": "type",
418
+
"types": {
419
+
"hotel": {
420
+
"dynamic": true,
421
+
"enabled": true
422
+
}
423
+
}
424
+
},
425
+
"store": {
426
+
"indexType": "scorch",
427
+
"segmentVersion": 15
428
+
}
429
+
},
430
+
"sourceType": "gocbcore",
431
+
"sourceName": "travel-sample",
432
+
"sourceUUID": "",
433
+
"sourceParams": {},
434
+
"planParams": {
435
+
"indexPartitions": 1
436
+
},
437
+
"uuid": ""
438
+
}
439
+
----
355
440
356
441
For more information on defining custom type mappings within the full text search index, refer to xref:fts:fts-type-mappings.adoc[Type Mappings].
357
442
Note that for N1QL queries, only full text search indexes with one type mapping are searchable.
@@ -506,6 +591,10 @@ AND SEARCH(t1, {
506
591
----
507
592
[
508
593
{
594
+
"meta": {
595
+
"id": "hotel_17598",
596
+
"score": 2.1256278997816835
597
+
},
509
598
"name": "Marina del Rey Marriott"
510
599
}
511
600
]
@@ -569,16 +658,19 @@ LIMIT 3;
569
658
----
570
659
[
571
660
{
572
-
"description": "3 Star Hotel next to the Mountain Railway terminus and set in 30 acres of grounds which include Dolbadarn Castle",
573
-
"name": "The Royal Victoria Hotel"
661
+
"description": "370 guest rooms offering both water and mountain view.",
662
+
"name": "Marina del Rey Marriott",
663
+
"score": 2.1256278997816835
574
664
},
575
665
{
576
-
"description": "370 guest rooms offering both water and mountain view.",
577
-
"name": "Marina del Rey Marriott"
666
+
"description": "Log cabin glamping in a rural setting with panoramic views toward the Clwydian Mountain Range.",
667
+
"name": "Clwydian Holidays",
668
+
"score": 1.6956645086702617
578
669
},
579
670
{
580
-
"description": "This small family run hotel captures the spirit of Mull and is a perfect rural holiday retreat. The mountain and sea blend together to give fantastic, panoramic views from the hotel which is in an elevated position on the shoreline. Panoramic views are also available from the bar and restaurant which serves local produce 7 days a week.",
581
-
"name": "The Glenforsa Hotel"
671
+
"description": "3 Star Hotel next to the Mountain Railway terminus and set in 30 acres of grounds which include Dolbadarn Castle",
672
+
"name": "The Royal Victoria Hotel",
673
+
"score": 1.5030458987111712
582
674
}
583
675
]
584
676
----
@@ -682,4 +774,4 @@ WHERE reviews.content LIKE "%travel%";
682
774
SELECT META().id
683
775
FROM `travel-sample`.`inventory`.`hotel` t USE INDEX(USING FTS)
To use any of the search functions, the Search service must be available on the cluster.
13
-
It is also recommended, but not required, that you should create suitable full text indexes for the searches that you need to perform.
13
+
It is required for you to create suitable full text indexes for the searches that you want to perform.
14
14
For more information, refer to xref:fts:fts-quickstart-guide.adoc#preparing-for-full-text-searches[Preparing for Full Text Searches].
15
15
16
16
[NOTE]
17
17
--
18
-
The examples in this page all assume that demonstration full text indexes have been created, as described in xref:fts:fts-demonstration-indexes.adoc[Demonstration Indexes].
18
+
The examples in this page assume that you have a full text search index created with this definition, unless specified otherwise ..
19
+
[source,json]
20
+
----
21
+
{
22
+
"name": "travel-sample-inventory-hotels",
23
+
"type": "fulltext-index",
24
+
"params": {
25
+
"doc_config": {
26
+
"mode": "scope.collection.type_field",
27
+
"type_field": "type"
28
+
},
29
+
"mapping": {
30
+
"default_analyzer": "standard",
31
+
"default_datetime_parser": "dateTimeOptional",
32
+
"default_field": "_all",
33
+
"default_mapping": {
34
+
"dynamic": true,
35
+
"enabled": false
36
+
},
37
+
"default_type": "_default",
38
+
"docvalues_dynamic": false,
39
+
"index_dynamic": true,
40
+
"store_dynamic": false,
41
+
"type_field": "_type",
42
+
"types": {
43
+
"inventory.hotel": {
44
+
"dynamic": true,
45
+
"enabled": true
46
+
}
47
+
}
48
+
},
49
+
"store": {
50
+
"indexType": "scorch",
51
+
"segmentVersion": 15
52
+
}
53
+
},
54
+
"sourceType": "gocbcore",
55
+
"sourceName": "travel-sample",
56
+
"sourceUUID": "",
57
+
"sourceParams": {},
58
+
"planParams": {
59
+
"indexPartitions": 1
60
+
},
61
+
"uuid": ""
62
+
}
63
+
----
64
+
19
65
--
20
66
21
67
[float]
@@ -211,33 +257,29 @@ The following queries are equivalent:
211
257
[source,n1ql]
212
258
----
213
259
SELECT META(t1).id
214
-
FROM `travel-sample`.inventory.airline AS t1
260
+
FROM `travel-sample`.inventory.hotel AS t1
215
261
WHERE SEARCH(t1.country, "+United +States");
216
262
----
217
263
218
264
[source,n1ql]
219
265
----
220
266
SELECT META(t1).id
221
-
FROM `travel-sample`.inventory.airline AS t1
267
+
FROM `travel-sample`.inventory.hotel AS t1
222
268
WHERE SEARCH(t1, "country:\"United States\"");
223
269
----
224
270
225
271
.Results
226
272
[source,json]
227
273
----
228
274
[
229
-
230
275
{
231
-
"id": "airline_10"
276
+
"id": "hotel_26215"
232
277
},
233
278
{
234
-
"id": "airline_10123"
279
+
"id": "hotel_7396"
235
280
},
236
281
{
237
-
"id": "airline_10226"
238
-
},
239
-
{
240
-
"id": "airline_10748"
282
+
"id": "hotel_32177"
241
283
},
242
284
...
243
285
]
@@ -334,7 +376,7 @@ As an alternative, you could limit the number of results and order them using th
334
376
[source,n1ql]
335
377
----
336
378
SELECT META(t1).id
337
-
FROM `travel-sample`.inventory.hotel AS t1
379
+
FROM `travel-sample` AS t1
338
380
WHERE t1.type = "hotel" AND SEARCH(t1.description, "amazing");
339
381
----
340
382
@@ -358,7 +400,51 @@ WHERE t1.type = "hotel" AND SEARCH(t1.description, "amazing");
358
400
----
359
401
360
402
If the full text search index being queried has its default mapping disabled and has a custom type mapping defined, the query needs to specify the type explicitly.
361
-
The above query uses the demonstration index xref:fts:fts-demonstration-indexes.adoc#travel-sample-index-hotel-description[travel-sample-index-hotel-description], which has the custom type mapping "hotel".
403
+
The above query uses the following index definition ..
404
+
[source,json]
405
+
----
406
+
{
407
+
"name": "travel-sample-hotels",
408
+
"type": "fulltext-index",
409
+
"params": {
410
+
"doc_config": {
411
+
"mode": "type_field",
412
+
"type_field": "type"
413
+
},
414
+
"mapping": {
415
+
"default_analyzer": "standard",
416
+
"default_datetime_parser": "dateTimeOptional",
417
+
"default_field": "_all",
418
+
"default_mapping": {
419
+
"dynamic": true,
420
+
"enabled": false
421
+
},
422
+
"default_type": "_default",
423
+
"index_dynamic": true,
424
+
"store_dynamic": true,
425
+
"type_field": "type",
426
+
"types": {
427
+
"hotel": {
428
+
"dynamic": true,
429
+
"enabled": true
430
+
}
431
+
}
432
+
},
433
+
"store": {
434
+
"indexType": "scorch",
435
+
"segmentVersion": 15
436
+
}
437
+
},
438
+
"sourceType": "gocbcore",
439
+
"sourceName": "travel-sample",
440
+
"sourceUUID": "",
441
+
"sourceParams": {},
442
+
"planParams": {
443
+
"indexPartitions": 1
444
+
},
445
+
"uuid": ""
446
+
}
447
+
----
362
448
363
449
For more information on defining custom type mappings within the full text search index, refer to xref:fts:fts-creating-indexes.adoc#specifying-type-mappings[Specifying Type Mappings].
364
450
Note that for N1QL queries, only full text search indexes with one type mapping are searchable.
@@ -513,6 +599,10 @@ AND SEARCH(t1, {
513
599
----
514
600
[
515
601
{
602
+
"meta": {
603
+
"id": "hotel_17598",
604
+
"score": 2.1256278997816835
605
+
},
516
606
"name": "Marina del Rey Marriott"
517
607
}
518
608
]
@@ -576,16 +666,19 @@ LIMIT 3;
576
666
----
577
667
[
578
668
{
579
-
"description": "3 Star Hotel next to the Mountain Railway terminus and set in 30 acres of grounds which include Dolbadarn Castle",
580
-
"name": "The Royal Victoria Hotel"
669
+
"description": "370 guest rooms offering both water and mountain view.",
670
+
"name": "Marina del Rey Marriott",
671
+
"score": 2.1256278997816835
581
672
},
582
673
{
583
-
"description": "370 guest rooms offering both water and mountain view.",
584
-
"name": "Marina del Rey Marriott"
674
+
"description": "Log cabin glamping in a rural setting with panoramic views toward the Clwydian Mountain Range.",
675
+
"name": "Clwydian Holidays",
676
+
"score": 1.6956645086702617
585
677
},
586
678
{
587
-
"description": "This small family run hotel captures the spirit of Mull and is a perfect rural holiday retreat. The mountain and sea blend together to give fantastic, panoramic views from the hotel which is in an elevated position on the shoreline. Panoramic views are also available from the bar and restaurant which serves local produce 7 days a week.",
588
-
"name": "The Glenforsa Hotel"
679
+
"description": "3 Star Hotel next to the Mountain Railway terminus and set in 30 acres of grounds which include Dolbadarn Castle",
0 commit comments