Masahiro Aoki
04/22/2021, 6:31 AMindex.search('query', {
facetFilters: 'Name:-John'
})
Kishore Nallan
04/22/2021, 6:34 AMMasahiro Aoki
04/22/2021, 6:36 AMKishore Nallan
04/22/2021, 6:36 AMMasahiro Aoki
04/22/2021, 6:41 AMlet documents = {
'id': '124',
'company_name': 'Stark Industries',
'num_employees': 5215,
'country': 'USA'
},
{
'id': '125',
'company_name': 'Apple',
'num_employees': 20000,
'country': 'USA'
},
Let’s say I have these documents.
When I want to retrieve the first data by filtering
company_name !==Stark Industries
How can I achieve this?Kishore Nallan
04/22/2021, 6:42 AM?q=-stark -industries
will exclude both those tokens from search results.Masahiro Aoki
04/22/2021, 6:45 AMKishore Nallan
04/22/2021, 6:46 AMcompany_name
Masahiro Aoki
04/22/2021, 6:49 AMlet searchParameters = {
'q':'company_name',
'query_by':'?q=-stark -industries',
}
const result = await client.collections('users').documents().search(searchParameters)
Kishore Nallan
04/22/2021, 6:50 AMlet searchParameters = {
'q':'-stark -industries',
'query_by':'company_name'
}
const result = await client.collections('users').documents().search(searchParameters)
Masahiro Aoki
04/22/2021, 6:52 AMq
? above example has 2 parameters.Masahiro Aoki
04/22/2021, 6:53 AMKishore Nallan
04/22/2021, 6:53 AMq
is a search query which is really a lust of keywords / tokens you are searching for. When a keyword is prefixed with a -
it just tell typesense to treat it as an exclusion explicitly. You can have as many tokens as you want, but as you add more tokens, things can become slower.Kishore Nallan
04/22/2021, 6:54 AMdrop_tokens_threshold
and typo_tokens_threshold
for performance.Kishore Nallan
04/22/2021, 6:54 AMMasahiro Aoki
04/22/2021, 6:54 AMKishore Nallan
04/22/2021, 6:54 AMMasahiro Aoki
04/22/2021, 7:19 AMKishore Nallan
04/22/2021, 7:19 AMMasahiro Aoki
04/22/2021, 8:16 AMconst userIdList = [''] // This contains 850 user ids
let searchParameters = {
'q':`${userIdList}`,
'query_by':'userId',
}
try{
const result = await client.collections('users').documents().search(searchParameters)
console.log(result['found']);
}catch(e){
console.log(e);
}
When I run this code in Typesense cluster,
These errors were emitted.
Request #1619079225148: Request to Node 0 failed due to "ECONNRESET socket hang up"
Request #1619079225148: Sleeping for 0.1s and then retrying request...
Request #1619079225148: Request to Node 0 failed due to "ECONNRESET socket hang up"
Request #1619079225148: Sleeping for 0.1s and then retrying request...
{ Error: socket hang up
at createHangUpError (_http_client.js:332:15)
at TLSSocket.socketOnEnd (_http_client.js:435:23)
at TLSSocket.emit (events.js:203:15)
at TLSSocket.EventEmitter.emit (domain.js:448:20)
at endReadableNT (_stream_readable.js:1145:12)
at process._tickCallback (internal/process/next_tick.js:63:19)
code: 'ECONNRESET',
Masahiro Aoki
04/22/2021, 8:17 AMMasahiro Aoki
04/22/2021, 8:21 AMRequest #1619079178557: Request to Node 0 failed due to "ECONNABORTED timeout of 2000ms exceeded"
Request #1619079178557: Sleeping for 0.1s and then retrying request...
Request #1619079178557: Request to Node 0 failed due to "ECONNRESET socket hang up"
Request #1619079178557: Sleeping for 0.1s and then retrying request...
Kishore Nallan
04/22/2021, 8:23 AMMasahiro Aoki
04/22/2021, 8:24 AMKishore Nallan
04/22/2021, 8:25 AMstring[]
. The q
parameter must be a string. The query_by
parameter must also be a comma separated string of field names.Kishore Nallan
04/22/2021, 8:26 AMMasahiro Aoki
04/22/2021, 8:28 AMMasahiro Aoki
04/22/2021, 8:28 AMKishore Nallan
04/22/2021, 8:31 AMMasahiro Aoki
04/22/2021, 8:31 AMKishore Nallan
04/22/2021, 8:32 AMuser1 user2 -user3
(here user3 is getting excluded)Masahiro Aoki
04/22/2021, 8:33 AMMasahiro Aoki
04/22/2021, 8:47 AMconst ids = list.toString().replace(/,/g,'');
let searchParameters = {
'q':`${ids}`,
'query_by':'userId',
}
try{
const result = await client.collections('users').documents().search(searchParameters)
console.log(result['found']);
}catch(e){
console.log(e);
}
I changed my code.
After changing up to 870 user id was excluded.Masahiro Aoki
04/22/2021, 8:48 AMRequest #1619081145364: Request to Node 0 failed due to "ECONNRESET socket hang up"
Request #1619081145364: Sleeping for 0.1s and then retrying request...
Request #1619081145364: Request to Node 0 failed due to "ECONNRESET socket hang up"
Request #1619081145364: Sleeping for 0.1s and then retrying request...
{ Error: socket hang up
at createHangUpError (_http_client.js:332:15)
at TLSSocket.socketOnEnd (_http_client.js:435:23)
at TLSSocket.emit (events.js:203:15)
at TLSSocket.EventEmitter.emit (domain.js:448:20)
at endReadableNT (_stream_readable.js:1145:12)
at process._tickCallback (internal/process/next_tick.js:63:19)
code: 'ECONNRESET',
Masahiro Aoki
04/22/2021, 8:49 AM-00DNZbtTCITocafJcAQQiwpNoHl1 -00WKEWPCPMhYNpUMWFxFOIDPyCr2 -00ZF115hfFRoUc7jKIfULuzQNWx1 -00bOGtDLzJY7X5KoMw3kTOuz7SG3 -00uuZMTjXiMTdYokCaFJakxqblI3
Kishore Nallan
04/22/2021, 8:51 AMnum_typos
to 0? The q
field is not technically meant to be used this way with so many tokens. So what I have suggested might not work for large values. In any cases, I think you should run Typesense locally on your machine and check the logs to see if some error shows up when you query this way. Or, the query might just be taking a really long time and timing out because of the number of tokens used.Masahiro Aoki
04/22/2021, 8:53 AMMasahiro Aoki
04/22/2021, 8:53 AMMasahiro Aoki
04/22/2021, 8:54 AMlet searchParameters = {
'q':`${ids}`,
'query_by':'userId',
'num_typos':'0',
}
Kishore Nallan
04/22/2021, 8:58 AMKishore Nallan
04/22/2021, 8:58 AM-
?Masahiro Aoki
04/22/2021, 8:59 AMKishore Nallan
04/22/2021, 9:00 AMMasahiro Aoki
04/22/2021, 9:00 AMMasahiro Aoki
04/22/2021, 9:01 AMKishore Nallan
04/22/2021, 9:01 AMMasahiro Aoki
04/22/2021, 9:02 AMKishore Nallan
04/22/2021, 9:02 AMKishore Nallan
04/22/2021, 9:44 AMmulti_search
endpoint (which uses POST) worked: https://typesense.org/docs/0.19.0/api/documents.html#federated-multi-search