I see there is a way to retrieve a document by id,...
# community-help
p
I see there is a way to retrieve a document by id, but is there an efficient way to retrieve more than one? GET ${TYPESENSE_HOST}/collections/collection/documents/id The use case is if a user "saves" some and wants to view them again later
k
👋 Available in the pre release build. You can try on the
typesense/typesense:0.22.0.rcs18
Docker image. You can do a filter on IDs via
filter_by=id: [1,2,3]
💯 2
p
awesome, do you have an estimate of when this might get released, and also to typesense cloud?
j
@Phil We're probably 2-3 weeks out from a public release, depending on if we find any other issues. On Typesense Cloud, we can upgrade your cluster to the latest RC from our side, if you email contact@typesense.org with your cluster ID
p
hmm I got it working building a query based off this issue you guys answered, I will look into this more myself, thanks:
@Kishore Nallan @Jason Bosco Thanks for this feature and the quick cloud upgrade, it works great. Is it currently planned to add it to the instant search adapter?
j
@Phil could you try using the latest pre-release version of the instant search adapter?
Also this might help provide some context around filter_by: https://github.com/typesense/typesense-instantsearch-adapter/issues/17 In the latest pre release version though, filter_by in additional search parameters is used if instantsearch’s widgets don’t override it
p
Thanks, that works with additionalSearchParameters. Ideally typesense-instantsearch-adapter would allow it to be set within the Configure widget so that users can still use other filtering, i.e.
<Configure facetFilters={["id:[id1,id2]"]} />
I looked at the code and the difference is that the SearchRequestAdapter.js will see id:[id1,id2] as string facets so they will be put into the filter_by with ":=", add escape characters "``", and not parse the array resulting in id:=[
[id1,id2]
] instead of id:[id1,id2] Is this a change that could be made?
@Jason Bosco @Kishore Nallan hi just seeing if you have seen this / have opinions on if this might be possible
j
@Phil Could you try this format:
<Configure facetFilters={[['id:id1', 'id:id2']]} />
Docs for that format is here: https://www.algolia.com/doc/api-reference/api-parameters/facetFilters/
p
@Jason Bosco I gave that a try and the adapter ends up querying like this, which does not work: `filter_by: id:=[
JzhGgJ6dQbrjkudNvaSj
,
TqLsp6OzikXF8iDhNLxW
]` It needs to omit the "=" and "`" to work. output that would work:
filter_by: id:[JzhGgJ6dQbrjkudNvaSj,TqLsp6OzikXF8iDhNLxW]
j
@Phil
Copy code
is just to escape the tokens, so in this case its presence should not affect results.
=` on the other had currently only works on faceted field. Does it through an error though?
If it does throw an error, could you try defining id as a faceted (string) field in the schema?
p
@Jason Bosco it does not throw an error when using
=
, it just returns no results. The backticks ``` do affect results for id (not for other fields that are faceted), tested hitting the api directly. Will defining id as a faceted field affect performance or is id already indexed in that way? I can do it that way but the enhancement to retrieve multiple id's without faceting will kind of fall to the side then.
j
The backticks ` do affect results for id (not for other fields that are faceted), tested hitting the api directly.
That's surprising to hear. When you say affected, does it return no results if you don't use backtick or just different results?
Will defining id as a faceted field affect performance
It will consume additional memory... Actually since you're already running an RC build, could you use 0.22.0.rcs29? That doesn't have the requirement to use faceted fields for
=
match.
p
@Jason Bosco It returns no results. I'm testing this on a data set of 2 with random id's so I'm not sure it would ever return different results. This works: `"filter_by": "otherFacetedField:=[
xyz
] && id:[JzhGgJ6dQbrjkudNvaSj,TqLsp6OzikXF8iDhNLxW]"` This with backticks on id returns no results: `"filter_by": "otherFacetedField:=[
xyz
] && id:[
JzhGgJ6dQbrjkudNvaSj
,
TqLsp6OzikXF8iDhNLxW
]"`
k
It's possible that filter by ID does not account for backticks, I will check that.
p
thanks for all the help
@Jason Bosco I gave rcs29 a try, it still shows no results when using `=`: This works:
"filter_by": "id:[JzhGgJ6dQbrjkudNvaSj,TqLsp6OzikXF8iDhNLxW]"
This returns no results:
"filter_by": "id:=[JzhGgJ6dQbrjkudNvaSj,TqLsp6OzikXF8iDhNLxW]"
k
I'm pretty sure this is a bug. I will be able to confirm later today.
Thanks for the help!
👍 1
@Phil This is fixed in this Docker build:
typesense/typesense:0.22.0.rcs30
-- can you please try it out?
p
@Kishore Nallan Tested it out, works perfect! ``` works,
:=
works, and all working smoothly with the instantsearch adapter, Configure widget, and facetFilters. Thanks!
🙌 1
k
Happy to hear, you're welcome!