Hi, I am trying to create a full text search index based on a regex on a key. I can understand from documentation how the regex expression works.
Our Ids are like this:
I want to get all events that start with “event:email:action:input:” and assign it to the mapping object that we created “email”
What should go on the “Doc ID with regex:” ?
Unfortunately when we built this capability, we opted for a simple approach, so we do not support capture groups. The portion of the key that matches the entire regular expression will be used for the resulting type. This makes it hard to extract portions of the key, particularly in the middle or end and not include the surrounding context in the type name.
One option, if all documents of type email start with event is to use the longer pattern ‘event:email’ as your pattern (and that then is the result type).
Another option is to use a pattern like
The \b will match word boundaries (which : satisfies). This is more brittle, and can match email showing up in other parts of the key if that is possible (you would have to examine your key naming convention closely).
Using that as the regex will work, but will only match documents with that exact text. I’d suggest adding the ^ character at the start to ensure it is anchored to the start of the key. And type name used in the FTS mapping will also need to be the full “event:email:action:input”.
I have created a field name employeeDetails which has concatenated information
would this regex work for searching ‘firstName:*:lastName’ in case the user don’t specify the middleName while searching
Thank @sreeks for being so quick. But I think I did not put my question correctly.
I have a large document and it has an embedded array object, for eg -
id : …
name : …
I am using fts to select for a document that has the country as GB and selected as true. The query is returning me a false positive. Just wanted to understand whether this can be handled by fts indexes.
Also, I came across this link which has a comment by @Gabriel_P1 saying that it can be handled by setting the correct index -
I could not find any concrete examples of how to search for the required combinations in an array of objects in couchbase.
A solution which I was thinking of is to flatten the object and store it in a field
for instance :
id : …
name : …
"territoryFlattened ": GB, false
"territoryFlattened ": US, true
while creating the query, the user could use a query on the flattened field.
And to use regex if he does not provide values for either of the attributes, so the query would be like the search for the match ‘"territoryFlattened ": GB, *’ or ‘"territoryFlattened ": *, false’
What are your thoughts on it, does it look workable?
I would be able to leverage fts completely without moving to GSI or having to write complex queries
Thanks in advance !!