Hi @beyer-stefan,
It’s difficult to work with just a fragment and no data, so hopefully this will help
-
Load the travel-sample test set
-
Make an index on hello and indexed and stored three top level fields title, name, and id. I will provide the JSON at the end with a curl command if you want to skip the UI search index creation.
-
After you make your index in the UI use the UI to search for Giverny in the UI you should get two (2) hits.
Here is the FTS code you need to do the same, of course update your USERNAME and PASSWORD in the code.
package main
import (
"fmt"
"time"
"log"
"github.com/couchbase/gocb/v2"
"github.com/couchbase/gocb/v2/search"
)
func main() {
cluster, err := gocb.Connect("couchbase://127.0.0.1", gocb.ClusterOptions{
Authenticator: gocb.PasswordAuthenticator{
Username: "some_user",
Password: "some_password",
},
})
if err != nil {
log.Fatal(err)
}
bucket := cluster.Bucket("travel-sample")
err = bucket.WaitUntilReady(5*time.Second, nil)
if err != nil {
log.Fatal(err)
}
// In the future you might need to use a new scoped index
// like "travel-sample.inventory.hello" but for pre 7.6 just use the
// legacy global index name of "hello"
matchResult, err := cluster.SearchQuery(
"hello",
search.NewMatchQuery("Giverny"),
&gocb.SearchOptions{
Limit: 3,
Fields: []string{"*"},
},
)
if err != nil {
log.Fatal(err)
}
for matchResult.Next() {
row := matchResult.Row()
docID := row.ID
var fields interface{}
err := row.Fields(&fields)
if err != nil {
log.Fatal(err)
}
fmt.Printf("Document ID: %s fields %v\n", docID, fields)
}
// always check for errors after iterating
err = matchResult.Err()
if err != nil {
log.Fatal(err)
}
}
The output of the program is as follows:
$ go run main.go
Document ID: hotel_10063 fields map[name:The Robins title:Giverny]
Document ID: hotel_10064 fields map[name:Le Clos Fleuri title:Giverny]
The index I used is as follows:
{
"name": "hello",
"type": "fulltext-index",
"params": {
"doc_config": {
"docid_prefix_delim": "",
"docid_regexp": "",
"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": false,
"enabled": true,
"properties": {
"id": {
"enabled": true,
"dynamic": false,
"fields": [
{
"include_in_all": true,
"index": true,
"name": "id",
"store": true,
"type": "text"
}
]
},
"name": {
"enabled": true,
"dynamic": false,
"fields": [
{
"include_in_all": true,
"index": true,
"name": "name",
"store": true,
"type": "text"
}
]
},
"title": {
"enabled": true,
"dynamic": false,
"fields": [
{
"include_in_all": true,
"index": true,
"name": "title",
"store": true,
"type": "text"
}
]
}
}
}
}
},
"store": {
"indexType": "scorch",
"segmentVersion": 15
}
},
"sourceType": "gocbcore",
"sourceName": "travel-sample",
"sourceParams": {},
"planParams": {
"maxPartitionsPerPIndex": 1024,
"indexPartitions": 1,
"numReplicas": 0
}
}
If you don’t want to use the UI put the above in legacy_def.json and load import it via the following cURL command:
curl -XPUT -H "Content-type:application/json" -u USERNAME:PASSWORD http://SERVER_IP:8094/api/index/hello -d @./legacy_def.json
Best
Jon Strabala
Principal Product Manager - Server