FTS with child-object/sub-document result

Hey guys, currently I’m a bit frustrated because my search doesn’t work the way i want or the way i tried. Maybe you know how I get the needed result.

Sample Doc:

 {
 	"docID": "b4465a10-58f6-11ea-82bc-153386aea6c0",
 	"docType": "dataset",
 	"animals": [{
			"type": "dog",
 			"name": "sam",
 			"color": "black"
 		},
 		{
 			"type": "cat",
 			"name": "lucy",
 			"color": "black"
 		}, {
 			"type": "dog",
			"name": "charly",
			"color": "blue"
 		}
 	]
 }

If I search something like “+animals.type: dog +animals.color:bl*”, I only want the result:

[{
		"type": "dog",
		"name": "sam",
		"color": "black"
	},
	{
		"type": "dog",
		"name": "charly",
		"color": "blue"
	}
]

Is that possible? Thanks in advance!

@Maroubra FTS returns document IDs for the search terms. So while searching across an array of JSON objects within a document it would look for the searched terms - in your case within fields: animals.type and animals.color.
The terms in these fields for the document are flattened out…

"animals.type": ["dog", "cat", "dog"]
"animals.color": ["black", "black", "blue"]

Unfortunately, as of today FTS will return results for your search terms that are present in the fields indexed and not necessarily within the same nested object within the array.

I believe we do have a ticket for this on our roadmap, although I can’t promise you at the moment on when we’ll make builds available with it.

Hi, just wanted to know whether this functionality is available.
Also, I could see another link with the same problem but it seems to have some solution suggested by Gabriel_P1.
Could you please have a look at it as well?

@Sachin,

This functionality is not yet supported natively in FTS, primarily due to reprioritisation.
As there is already a way to achieve this over N1QL-FTS query as mentioned in the other post you were referring to.
ref - FTS inside array ( i suppose this)

Cheers!

@abhinav I am facing similar issue, here is the sample document :
{
“name”: “John Smith”,
“type”: “addrDoc”,
“addresses”: [
{
“street”: “123 Main St”,
“city”: “VA BEACH”,
“state”: “CA”,
“zip”: “12345”
},
{
“street”: “456 Oak St”,
“city”: “Othertown”,
“state”: “CA”,
“zip”: “67890”
}
]
}

I am expecting the below search result when I search with " addresses.city:beach "

{
“city”: “VA BEACH”,
“id”: “ADDR03”,
“state”: “CA”,
“street”: “123 Main St”,
“zip”: “12345”
}

Please share the details if couchbase has fixed this issue ? if not what is the best way to handle this issue.

Thank you

@Satya_rva The search engine flattens array objects and does not retain the array positions of these objects.

So for your example, (assuming you’ve used a standard analyzer) this is what the index would contain for these fields for doc ADDR03:

name = ["john", "smith"]
type = ["addrdoc"]
addresses.street = ["123", "main", "st", "456", "oak", "st"]
addresses.city = ["va", "beach", "othertown"]
addresses.state = ["ca", "ca"]
addresses.zip = ["12345", "67890"]

So when you look up addresses.city:beach - the document would be a hit, but if you request the fields alongside the hit.ID from the index - you would see the above flattened structure.

Indexing array object positions is something we’re considering to improve on but haven’t just yet.