Hi folks. I'm searching across multiple nested fie...
# community-help
j
Hi folks. I'm searching across multiple nested fields and seeing unexpected results. I would expect it to combine matches from all the fields in the query_by by it seems like it only takes matches from the first one, even when I use query_by_weights to make weight them equally. For example, I have documents with a name field that has a subfield for each locale:
Copy code
"name": {
                    "primary": "Tour Eiffel",
                    "en_us": "Eiffel Tower",
                    "es_es": "Torre Eiffel",
                    "fr_fr": "Tour Eiffel",
                    "ru_ru": "Эйфелева башня",
...
                }
In the schema we index all the nested name fields (name.primary, name.en_us, name.es__es...)._ Each of the nested fields has the corresponding locale set. When I query with the Russian name (Эйфелева башня) in name.* I get six results, none that match name.ru_ru even though it is an exact match for document 83300a0000000000.
Copy code
% curl 'http://localhost:8108/collections/public_places/documents/search?q=%D0%AD%D0%B9%D1%84%D0%B5%D0%BB%D0%B5%D0%B2%D0%B0%20%D0%B1%D0%B0%D1%88%D0%BD%D1%8F&query_by=name.*&query_by_weights=1' -H "X-TYPESENSE-API-KEY: $TYPESENSE_API_KEY" | jq ".hits[].document.name.ru_ru"          
null
null
null
null
null
null
If I search in just name.ru_ru without the other name fields then I get the match with document 83300a0000000000 as I would expect.
Copy code
curl 'http://localhost:8108/collections/public_places/documents/search?q=%D0%AD%D0%B9%D1%84%D0%B5%D0%BB%D0%B5%D0%B2%D0%B0%20%D0%B1%D0%B0%D1%88%D0%BD%D1%8F&query_by=name.ru_ru&query_by_weights=1' -H "X-TYPESENSE-API-KEY: $TYPESENSE_API_KEY" | jq ".hits[].document.name.ru_ru"
"Эйфелева башня"
Trying to narrow it down, if I search with the two fields name.ru_ru and name.primary with equal weights, I get different results depending on the order. Putting ru_ru first finds the doc but putting primary first does not. ru_ru first:
Copy code
curl 'http://localhost:8108/collections/public_places/documents/search?q=%D0%AD%D0%B9%D1%84%D0%B5%D0%BB%D0%B5%D0%B2%D0%B0%20%D0%B1%D0%B0%D1%88%D0%BD%D1%8F&query_by=name.ru_ru,name.primary&query_by_weights=1,1' -H "X-TYPESENSE-API-KEY: $TYPESENSE_API_KEY" | jq ".hits[].document.name.ru_ru"
"Эйфелева башня"
primary first:
Copy code
curl 'http://localhost:8108/collections/public_places/documents/search?q=%D0%AD%D0%B9%D1%84%D0%B5%D0%BB%D0%B5%D0%B2%D0%B0%20%D0%B1%D0%B0%D1%88%D0%BD%D1%8F&query_by=name.primary,name.ru_ru&query_by_weights=1,1' -H "X-TYPESENSE-API-KEY: $TYPESENSE_API_KEY" | jq ".hits[].document.name.ru_ru"
null
null
null
null
null
null
So it looks like it only considers the first field in the query_by list, however if I add extra weight to the second field it takes only results that match that one and not the other:
Copy code
curl 'http://localhost:8108/collections/public_places/documents/search?q=%D0%AD%D0%B9%D1%84%D0%B5%D0%BB%D0%B5%D0%B2%D0%B0%20%D0%B1%D0%B0%D1%88%D0%BD%D1%8F&query_by=name.primary,name.ru_ru&query_by_weights=1,2' -H "X-TYPESENSE-API-KEY: $TYPESENSE_API_KEY" | jq ".hits[].document.name.ru_ru"
"Эйфелева башня"
Attaching schema & docs in 🧵
This script sets up the collection and the sample docs
Anyone have a suggestion for a workaround?
a
Hey @Josh Handley I think the workaround for that is using federated search: https://typesense.org/docs/29.0/api/federated-multi-search.html
j
Thank @Alan Martini. We will give that a try and see. I assume you mean doing a federated search where there is a query for each locale (name.principal, name.en, name.fr, name.es...). That will end up being ~30 queries in our system. A bit concerned about performance but we will give it a try.