-
Notifications
You must be signed in to change notification settings - Fork 184
DOC-9450: Update SEARCH_META(..) instructions and examples #2468
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -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,33 +249,29 @@ 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\""); | ||||||
---- | ||||||
|
||||||
.Results | ||||||
[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 .. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
[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%"; | ||||||
---- | ||||||
---- |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.