Hi @vsr1 , @jon.strabala
I have a funcationality where I need to filter results from a document based on full text search.
Below is the document JSON which includes the fields that are in use for FTS.
JSON DOC
{
“clientId”:“6b643e3ff209”,
“groupId”:“DP-1”,
“id”:“dc26445b-e1d0-42be-b9a3-d0e18aa63ddf”,
“items”:[
“a1”,
“a2”
],
“priority”:999,
“tenantId”:“ecommerce”,
“type”:“group”,
“useCase”:[
{
“disabled”:true,
“externalIds”:[
“wb-98bded7a-95a0-4120-8f1d-007db7c30728”
],
“label”:“Use Case 1”,
“name”:“useCase1”
},
{
“disabled”:true,
“externalIds”:[
“wb-c335aa93-c8b4-40d9-9f50-ba01041d5dcd”
],
“label”:“Use Case 2”,
“name”:“useCase2”
}
]
}
FTS Index Configuration
Query
WITH results AS (
SELECT SEARCH_META(filteredUseCase) AS entry
FROM bucket-a
AS doc
WHERE SEARCH(doc, { “size” : 1,
“fields” : [“*”],
“sort”: [ { “by” : “field”, “field” : “priority”, “mode” : “max”, “missing” : “last”, “type”: “number” },
{ “by” : “field”, “field” : “modifiedOn”, “mode” : “max”, “missing” : “last”, “type”: “number”, “desc”:TRUE } ],
“query”: {“conjuncts”:
[ {“field”:“items”, “match”: “a2”},
{“field”:“tenantId”, “match”:“ecommerce”},
{“field”:“clientId”, “match”:“6b643e3ff209”},
{“field”:“useCase.name”, “match”:“useCase2”}
]
}
},
{“index”:“groupTestIndex”, “out” : “filteredUseCase”}
)
AND doc.type = “group”)
SELECT filteredDoc.entry.fields.useCase.externalIds
AS externalIds,
filteredDoc.entry.id AS groupId FROM results AS filteredDoc;
Query Result
[
{
“externalIds”: [
“wb-98bded7a-95a0-4120-8f1d-007db7c30728”,
“wb-c335aa93-c8b4-40d9-9f50-ba01041d5dcd”
],
“groupId”: “dc26445b-e1d0-42be-b9a3-d0e18aa63ddf”
}
]
I am expecting the result to come as only
[
{
“externalIds”: [
“wb-c335aa93-c8b4-40d9-9f50-ba01041d5dcd”
],
“groupId”: “dc26445b-e1d0-42be-b9a3-d0e18aa63ddf”
}
]
Currently , It is correctly matching the doc and giving out the useCase.externalIds as collection of all externalIds array under useCase array, while my flow is to only return those externalIds values where the usecase matched which was passed in the query.
Thanks
Harinder Singh