diff --git a/modules/fts/pages/fts-quickstart-guide.adoc b/modules/fts/pages/fts-quickstart-guide.adoc index 630450c8b0..ea489b886e 100644 --- a/modules/fts/pages/fts-quickstart-guide.adoc +++ b/modules/fts/pages/fts-quickstart-guide.adoc @@ -47,5 +47,4 @@ Refer to xref:n1ql:n1ql-language-reference/searchfun.adoc[Search Functions] for == Establishing Demonstration Indexes The Java SDK code-example provided in xref:java-sdk:howtos:full-text-searching-with-sdk.adoc[Searching from the SDK] contains multiple demonstration calls — each featuring a different query-combination — and makes use of three different index-definitions, related to the `travel-sample` bucket: for the code example to run successfully, the three indexes must be appropriately pre-established. -//The definitions are provided in xref:fts-demonstration-indexes.adoc[Demonstration Indexes]. Instructions on how to use the Couchbase REST API to establish the definitions refer to xref:fts-creating-index-with-rest-api.adoc[Creating Index with REST API]. diff --git a/modules/fts/pages/fts-searching-from-N1QL.adoc b/modules/fts/pages/fts-searching-from-N1QL.adoc index 9b77e89aa4..9e21520a27 100644 --- a/modules/fts/pages/fts-searching-from-N1QL.adoc +++ b/modules/fts/pages/fts-searching-from-N1QL.adoc @@ -5,11 +5,57 @@ Search functions enable you to use full text search queries directly within a N1 == Prerequisites To use any of the search functions, the Search service must be available on the cluster. -It is also recommended, but not required, that you should create suitable full text indexes for the searches that you need to perform. +It is required for you to create suitable full text indexes for the searches that you want to perform. [NOTE] -- -The examples in this page all assume that demonstration full text indexes have been created. +The examples in this page assume that you have a full text search index created with this definition, unless specified otherwise .. +[source,json] +---- +{ + "name": "travel-sample-inventory-hotels", + "type": "fulltext-index", + "params": { + "doc_config": { + "mode": "scope.collection.type_field", + "type_field": "type" + }, + "mapping": { + "default_analyzer": "standard", + "default_datetime_parser": "dateTimeOptional", + "default_field": "_all", + "default_mapping": { + "dynamic": true, + "enabled": false + }, + "default_type": "_default", + "docvalues_dynamic": false, + "index_dynamic": true, + "store_dynamic": false, + "type_field": "_type", + "types": { + "inventory.hotel": { + "dynamic": true, + "enabled": true + } + } + }, + "store": { + "indexType": "scorch", + "segmentVersion": 15 + } + }, + "sourceType": "gocbcore", + "sourceName": "travel-sample", + "sourceUUID": "", + "sourceParams": {}, + "planParams": { + "indexPartitions": 1 + }, + "uuid": "" +} +---- + -- === Authorization @@ -203,14 +249,14 @@ The following queries are equivalent: [source,n1ql] ---- SELECT META(t1).id -FROM `travel-sample`.inventory.airline AS t1 +FROM `travel-sample`.inventory.hotel AS t1 WHERE SEARCH(t1.country, "+United +States"); ---- [source,n1ql] ---- SELECT META(t1).id -FROM `travel-sample`.inventory.airline AS t1 +FROM `travel-sample`.inventory.hotel AS t1 WHERE SEARCH(t1, "country:\"United States\""); ---- @@ -218,18 +264,14 @@ WHERE SEARCH(t1, "country:\"United States\""); [source,json] ---- [ - { - "id": "airline_10" + "id": "hotel_26215" }, { - "id": "airline_10123" + "id": "hotel_7396" }, { - "id": "airline_10226" - }, - { - "id": "airline_10748" + "id": "hotel_32177" }, ... ] @@ -350,8 +392,51 @@ WHERE t1.type = "hotel" AND SEARCH(t1.description, "amazing"); ---- 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. - -//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". +The above query uses the following index definition .. +[source,json] +---- +{ + "name": "travel-sample-hotels", + "type": "fulltext-index", + "params": { + "doc_config": { + "mode": "type_field", + "type_field": "type" + }, + "mapping": { + "default_analyzer": "standard", + "default_datetime_parser": "dateTimeOptional", + "default_field": "_all", + "default_mapping": { + "dynamic": true, + "enabled": false + }, + "default_type": "_default", + "index_dynamic": true, + "store_dynamic": true, + "type_field": "type", + "types": { + "hotel": { + "dynamic": true, + "enabled": true + } + } + }, + "store": { + "indexType": "scorch", + "segmentVersion": 15 + } + }, + "sourceType": "gocbcore", + "sourceName": "travel-sample", + "sourceUUID": "", + "sourceParams": {}, + "planParams": { + "indexPartitions": 1 + }, + "uuid": "" +} +---- For more information on defining custom type mappings within the full text search index, refer to xref:fts:fts-type-mappings.adoc[Type Mappings]. Note that for N1QL queries, only full text search indexes with one type mapping are searchable. @@ -506,6 +591,10 @@ AND SEARCH(t1, { ---- [ { + "meta": { + "id": "hotel_17598", + "score": 2.1256278997816835 + }, "name": "Marina del Rey Marriott" } ] @@ -569,16 +658,19 @@ LIMIT 3; ---- [ { - "description": "3 Star Hotel next to the Mountain Railway terminus and set in 30 acres of grounds which include Dolbadarn Castle", - "name": "The Royal Victoria Hotel" + "description": "370 guest rooms offering both water and mountain view.", + "name": "Marina del Rey Marriott", + "score": 2.1256278997816835 }, { - "description": "370 guest rooms offering both water and mountain view.", - "name": "Marina del Rey Marriott" + "description": "Log cabin glamping in a rural setting with panoramic views toward the Clwydian Mountain Range.", + "name": "Clwydian Holidays", + "score": 1.6956645086702617 }, { - "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.", - "name": "The Glenforsa Hotel" + "description": "3 Star Hotel next to the Mountain Railway terminus and set in 30 acres of grounds which include Dolbadarn Castle", + "name": "The Royal Victoria Hotel", + "score": 1.5030458987111712 } ] ---- @@ -682,4 +774,4 @@ WHERE reviews.content LIKE "%travel%"; SELECT META().id FROM `travel-sample`.`inventory`.`hotel` t USE INDEX(USING FTS) WHERE content LIKE "%travel%"; ----- \ No newline at end of file +---- diff --git a/modules/fts/pages/fts-supported-queries-geo-spatial.adoc b/modules/fts/pages/fts-supported-queries-geo-spatial.adoc index 078da71b7c..e15fb13e74 100644 --- a/modules/fts/pages/fts-supported-queries-geo-spatial.adoc +++ b/modules/fts/pages/fts-supported-queries-geo-spatial.adoc @@ -232,8 +232,61 @@ For initial experimentation with geospatial querying, the `geo` field of documen [#fts_geopoint_definition] image::fts-geopoint-definition.png[,620,align=left] -The index so created can also be specified by means of the Couchbase REST API. -See xref:fts-demonstration-indexes.adoc[Demonstration Indexes] for the body of the index to be used, and see xref:fts-creating-index-with-rest-api.adoc[Index Creation with the REST API] for information on using the REST syntax. +The following query examples in this page will require the following index definition .. + +[source,json] +---- +{ + "type": "fulltext-index", + "name": "geoIndex", + "uuid": "", + "sourceType": "gocbcore", + "sourceName": "travel-sample", + "sourceUUID": "", + "planParams": { + "indexPartitions": 1 + }, + "params": { + "doc_config": { + "mode": "type_field", + "type_field": "type" + }, + "mapping": { + "default_analyzer": "standard", + "default_datetime_parser": "dateTimeOptional", + "default_field": "_all", + "default_mapping": { + "dynamic": true, + "enabled": true, + "properties": { + "geo": { + "dynamic": false, + "enabled": true, + "fields": [ + { + "include_in_all": true, + "include_term_vectors": true, + "index": true, + "name": "geo", + "store": true, + "type": "geopoint" + } + ] + } + } + }, + "default_type": "_default", + "index_dynamic": true, + "store_dynamic": false + }, + "store": { + "indexType": "scorch", + "segmentVersion": 15 + } + }, + "sourceParams": {} +} +---- [#creating_geospatial_rest_query_radius_based] === Creating a Query: Radius-Based diff --git a/modules/n1ql/pages/n1ql-language-reference/searchfun.adoc b/modules/n1ql/pages/n1ql-language-reference/searchfun.adoc index 39b0cabb97..49a839dc71 100644 --- a/modules/n1ql/pages/n1ql-language-reference/searchfun.adoc +++ b/modules/n1ql/pages/n1ql-language-reference/searchfun.adoc @@ -10,12 +10,58 @@ === Prerequisites To use any of the search functions, the Search service must be available on the cluster. -It is also recommended, but not required, that you should create suitable full text indexes for the searches that you need to perform. +It is required for you to create suitable full text indexes for the searches that you want to perform. For more information, refer to xref:fts:fts-quickstart-guide.adoc#preparing-for-full-text-searches[Preparing for Full Text Searches]. [NOTE] -- -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]. +The examples in this page assume that you have a full text search index created with this definition, unless specified otherwise .. +[source,json] +---- +{ + "name": "travel-sample-inventory-hotels", + "type": "fulltext-index", + "params": { + "doc_config": { + "mode": "scope.collection.type_field", + "type_field": "type" + }, + "mapping": { + "default_analyzer": "standard", + "default_datetime_parser": "dateTimeOptional", + "default_field": "_all", + "default_mapping": { + "dynamic": true, + "enabled": false + }, + "default_type": "_default", + "docvalues_dynamic": false, + "index_dynamic": true, + "store_dynamic": false, + "type_field": "_type", + "types": { + "inventory.hotel": { + "dynamic": true, + "enabled": true + } + } + }, + "store": { + "indexType": "scorch", + "segmentVersion": 15 + } + }, + "sourceType": "gocbcore", + "sourceName": "travel-sample", + "sourceUUID": "", + "sourceParams": {}, + "planParams": { + "indexPartitions": 1 + }, + "uuid": "" +} +---- + -- [float] @@ -88,7 +134,7 @@ For more details, refer to xref:fts:fts-query-types.adoc#query-string-query-synt | object | The query object within a full text search request. -For more details, refer to xref:fts-supported-queries.adoc[Supported Queries]. +For more details, refer to xref:fts:fts-supported-queries.adoc[Supported Queries]. | object | A complete full text search request, including sort and pagination options, and so on. @@ -211,14 +257,14 @@ The following queries are equivalent: [source,n1ql] ---- SELECT META(t1).id -FROM `travel-sample`.inventory.airline AS t1 +FROM `travel-sample`.inventory.hotel AS t1 WHERE SEARCH(t1.country, "+United +States"); ---- [source,n1ql] ---- SELECT META(t1).id -FROM `travel-sample`.inventory.airline AS t1 +FROM `travel-sample`.inventory.hotel AS t1 WHERE SEARCH(t1, "country:\"United States\""); ---- @@ -226,18 +272,14 @@ WHERE SEARCH(t1, "country:\"United States\""); [source,json] ---- [ - { - "id": "airline_10" + "id": "hotel_26215" }, { - "id": "airline_10123" + "id": "hotel_7396" }, { - "id": "airline_10226" - }, - { - "id": "airline_10748" + "id": "hotel_32177" }, ... ] @@ -334,7 +376,7 @@ As an alternative, you could limit the number of results and order them using th [source,n1ql] ---- SELECT META(t1).id -FROM `travel-sample`.inventory.hotel AS t1 +FROM `travel-sample` AS t1 WHERE t1.type = "hotel" AND SEARCH(t1.description, "amazing"); ---- @@ -358,7 +400,51 @@ WHERE t1.type = "hotel" AND SEARCH(t1.description, "amazing"); ---- 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. -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". +The above query uses the following index definition .. +[source,json] +---- +{ + "name": "travel-sample-hotels", + "type": "fulltext-index", + "params": { + "doc_config": { + "mode": "type_field", + "type_field": "type" + }, + "mapping": { + "default_analyzer": "standard", + "default_datetime_parser": "dateTimeOptional", + "default_field": "_all", + "default_mapping": { + "dynamic": true, + "enabled": false + }, + "default_type": "_default", + "index_dynamic": true, + "store_dynamic": true, + "type_field": "type", + "types": { + "hotel": { + "dynamic": true, + "enabled": true + } + } + }, + "store": { + "indexType": "scorch", + "segmentVersion": 15 + } + }, + "sourceType": "gocbcore", + "sourceName": "travel-sample", + "sourceUUID": "", + "sourceParams": {}, + "planParams": { + "indexPartitions": 1 + }, + "uuid": "" +} +---- 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]. Note that for N1QL queries, only full text search indexes with one type mapping are searchable. @@ -513,6 +599,10 @@ AND SEARCH(t1, { ---- [ { + "meta": { + "id": "hotel_17598", + "score": 2.1256278997816835 + }, "name": "Marina del Rey Marriott" } ] @@ -576,16 +666,19 @@ LIMIT 3; ---- [ { - "description": "3 Star Hotel next to the Mountain Railway terminus and set in 30 acres of grounds which include Dolbadarn Castle", - "name": "The Royal Victoria Hotel" + "description": "370 guest rooms offering both water and mountain view.", + "name": "Marina del Rey Marriott", + "score": 2.1256278997816835 }, { - "description": "370 guest rooms offering both water and mountain view.", - "name": "Marina del Rey Marriott" + "description": "Log cabin glamping in a rural setting with panoramic views toward the Clwydian Mountain Range.", + "name": "Clwydian Holidays", + "score": 1.6956645086702617 }, { - "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.", - "name": "The Glenforsa Hotel" + "description": "3 Star Hotel next to the Mountain Railway terminus and set in 30 acres of grounds which include Dolbadarn Castle", + "name": "The Royal Victoria Hotel", + "score": 1.5030458987111712 } ] ----