Slackbot
10/09/2023, 9:01 AMKishore Nallan
10/09/2023, 9:02 AMAadarsh
10/09/2023, 9:02 AMAadarsh
10/09/2023, 9:03 AM0.25.1 earlier but I want to use JOINsKishore Nallan
10/09/2023, 9:34 AMAadarsh
10/09/2023, 9:35 AMcommon_search_params = {'query_by': 'name,code'}Kishore Nallan
10/09/2023, 9:36 AMAadarsh
10/09/2023, 10:08 AMsearch.py
import typesense
client = typesense.Client(
{
"nodes": [
{
"host": host, # For Typesense Cloud use xxx.a1.typesense.net
"port": port, # For Typesense Cloud use 443
"protocol": protocol, # For Typesense Cloud use https
}
],
"api_key": api_key,
"connection_timeout_seconds": connection_timeout_seconds,
}
)
collection1 = {
"name": "collection1",
"fields": [
{
"name": "name",
"type": "string",
"facet": True,
},
{
"name": "priority",
"type": "int32",
"facet": True,
},
{
"name": "code",
"type": "string",
"facet": True,
},
],
}
document1 = [
{"name": "Pizza", "priority": 53, "code": "0"},
{"name": "Burger", "priority": 20, "code": "1"},
{"name": "Cake", "priority": 23, "code": "2"},
{"name": "Kiosk", "priority": 72, "code": "3"},
{"name": "Icecream", "priority": 49, "code": "4"},
]
client.collections.create(collection1)
client.collections["collection1"].documents.import_(document1)
collection2 = {
"name": "collection2",
"fields": [
{
"name": "name",
"type": "string",
"facet": True,
},
{
"name": "priority",
"type": "int32",
"facet": True,
},
{
"name": "code",
"type": "string",
"facet": True,
"reference": "collection1.code",
},
{
"name": "name_tag",
"type": "string[]",
"facet": True,
},
],
}
document2 = [
{"name": "Pizza", "priority": 53, "code": "0", "name_tag": ["0"]},
{"name": "Burger", "priority": 20, "code": "1", "name_tag": ["1"]},
{"name": "Cake", "priority": 23, "code": "2", "name_tag": ["2"]},
{"name": "Kiosk", "priority": 72, "code": "3", "name_tag": ["3"]},
{"name": "Icecream", "priority": 49, "code": "4", "name_tag": ["4"]},
]
client.collections.create(collection2)
client.collections["collection2"].documents.import_(document2)
def retreive_collection(collection_name, verbose=False):
client.collections[collection_name].retrieve()
if verbose:
print(f'"{collection_name}" retreived successfully')
return
collection_names = ["collection1", "collection2"]
filtered_search_requests = list()
for collection in collection_names:
search_request = dict()
search_request["collection"] = collection
search_request["q"] = "pizza"
search_request["sort_by"] = "priority:desc,_text_match:desc"
search_request["prioritize_token_position"] = "true"
if collection=="collection2":
search_request["filter_by"] = "$collection1(code:=name_tag)"
filtered_search_requests.append(search_request)
search_requests = {"searches": filtered_search_requests}
common_search_params = {
"query_by": "name,code",
}
for collection in collection_names:
retreive_collection(collection_name=collection)
response = client.multi_search.perform(search_requests, common_search_params)
print(response)
Docker run command: docker run -p 8108:8108 -v/tmp/data:/data typesense/typesense:0.26.0.rc22 --data-dir /data --api-key=$api_key
Python run command: python search.py
Error: typesense.exceptions.RequestMalformed: [Errno 400] One or more search parameters are malformed.Aadarsh
10/09/2023, 10:17 AMKishore Nallan
10/09/2023, 10:18 AMKishore Nallan
10/09/2023, 10:49 AMsearch_request["filter_by"] = ("$tags(code:=name_tag)",)Aadarsh
10/09/2023, 11:20 AM{
"results": [
{
"facet_counts": [],
"found": 0,
"hits": [],
"out_of": 0,
"page": 1,
"request_params": {
"collection_name": "collection1",
"per_page": 10,
"q": "pizza"
},
"search_cutoff": false,
"search_time_ms": 0
},
{
"facet_counts": [],
"found": 0,
"hits": [],
"out_of": 0,
"page": 1,
"request_params": {
"collection_name": "collection2",
"per_page": 10,
"q": "pizza"
},
"search_cutoff": false,
"search_time_ms": 0
}
]
}
It's not getting any matches in the response and hence I'm not able to test the build. Please suggest if there's any other update in the code. Thanks!Harpreet Sangar
10/09/2023, 11:39 AMcollection1 or collection2.Harpreet Sangar
10/09/2023, 11:40 AMpriority field which is absent in the documents. Also both the responses have:
"out_of": 0,Aadarsh
10/09/2023, 11:47 AMAadarsh
10/10/2023, 5:16 AMimport typesense
client = typesense.Client(
{
"nodes": [
{
"host": host, # For Typesense Cloud use xxx.a1.typesense.net
"port": port, # For Typesense Cloud use 443
"protocol": protocol, # For Typesense Cloud use https
}
],
"api_key": api_key,
"connection_timeout_seconds": connection_timeout_seconds,
}
)
collection1 = {
"name": "collection1",
"fields": [
{
"name": "name",
"type": "string",
"facet": True,
},
{
"name": "priority",
"type": "int32",
"facet": True,
},
{
"name": "code",
"type": "string",
"facet": True,
},
],
}
document1 = [
{"name": "tags Pizza", "priority": 53, "code": "0"},
{"name": "Burger", "priority": 20, "code": "1"},
{"name": "Cake", "priority": 23, "code": "2"},
{"name": "Kiosk", "priority": 72, "code": "3"},
{"name": "Icecream", "priority": 49, "code": "4"},
]
client.collections.create(collection1)
client.collections["collection1"].documents.import_(document1)
collection2 = {
"name": "collection2",
"fields": [
{
"name": "name",
"type": "string",
"facet": True,
},
{
"name": "priority",
"type": "int32",
"facet": True,
},
{
"name": "code",
"type": "string",
"facet": True,
"reference": "collection1.code",
},
{
"name": "name_tag",
"type": "string[]",
"facet": True,
},
],
}
document2 = [
{"name": "Pizza", "priority": 53, "code": "0", "name_tag": ["0", "1"]},
{"name": "Burger", "priority": 20, "code": "1", "name_tag": ["1"]},
{"name": "Cake", "priority": 23, "code": "2", "name_tag": ["2"]},
{"name": "Kiosk", "priority": 72, "code": "3", "name_tag": ["3"]},
{"name": "Icecream", "priority": 49, "code": "4", "name_tag": ["4"]},
]
client.collections.create(collection2)
client.collections["collection2"].documents.import_(document2)
def retreive_collection(collection_name, verbose=False):
client.collections[collection_name].retrieve()
if verbose:
print(f'"{collection_name}" retreived successfully')
return
collection_names = ["collection1", "collection2"]
filtered_search_requests = list()
for collection in collection_names:
search_request = dict()
search_request["collection"] = collection
search_request["q"] = "pizza"
search_request["sort_by"] = "priority:desc,_text_match:desc"
search_request["prioritize_token_position"] = "true"
if collection=="collection2":
search_request["filter_by"] = "$collection1(code:=name_tag)"
filtered_search_requests.append(search_request)
search_requests = {"searches": filtered_search_requests}
common_search_params = {
"query_by": "name,code",
}
for collection in collection_names:
retreive_collection(collection_name=collection)
response = client.multi_search.perform(search_requests, common_search_params)
print(response)
The response:
{
"results": [
{
"facet_counts": [],
"found": 4,
"hits": [
{
"document": {
"code": "0",
"id": "50",
"name": "Pizza",
"priority": 53
},
"highlight": {
"name": {
"matched_tokens": [
"Pizza"
],
"snippet": "<mark>Pizza</mark>"
}
},
"highlights": [
{
"field": "name",
"matched_tokens": [
"Pizza"
],
"snippet": "<mark>Pizza</mark>"
}
],
"text_match": 578730123366232200,
"text_match_info": {
"best_field_score": "1108091339262",
"best_field_weight": 15,
"fields_matched": 1,
"score": "578730123366232185",
"tokens_matched": 1
}
},
{
"document": {
"code": "0",
"id": "45",
"name": "Pizza",
"priority": 53
},
"highlight": {
"name": {
"matched_tokens": [
"Pizza"
],
"snippet": "<mark>Pizza</mark>"
}
},
"highlights": [
{
"field": "name",
"matched_tokens": [
"Pizza"
],
"snippet": "<mark>Pizza</mark>"
}
],
"text_match": 578730123366232200,
"text_match_info": {
"best_field_score": "1108091339262",
"best_field_weight": 15,
"fields_matched": 1,
"score": "578730123366232185",
"tokens_matched": 1
}
},
{
"document": {
"code": "0",
"id": "60",
"name": "tags Pizza",
"priority": 53
},
"highlight": {
"name": {
"matched_tokens": [
"Pizza"
],
"snippet": "tags <mark>Pizza</mark>"
}
},
"highlights": [
{
"field": "name",
"matched_tokens": [
"Pizza"
],
"snippet": "tags <mark>Pizza</mark>"
}
],
"text_match": 578730123365705900,
"text_match_info": {
"best_field_score": "1108091339005",
"best_field_weight": 15,
"fields_matched": 1,
"score": "578730123365705849",
"tokens_matched": 1
}
},
{
"document": {
"code": "0",
"id": "55",
"name": "tags Pizza",
"priority": 53
},
"highlight": {
"name": {
"matched_tokens": [
"Pizza"
],
"snippet": "tags <mark>Pizza</mark>"
}
},
"highlights": [
{
"field": "name",
"matched_tokens": [
"Pizza"
],
"snippet": "tags <mark>Pizza</mark>"
}
],
"text_match": 578730123365705900,
"text_match_info": {
"best_field_score": "1108091339005",
"best_field_weight": 15,
"fields_matched": 1,
"score": "578730123365705849",
"tokens_matched": 1
}
}
],
"out_of": 20,
"page": 1,
"request_params": {
"collection_name": "collection1",
"per_page": 10,
"q": "pizza"
},
"search_cutoff": false,
"search_time_ms": 2
},
{
"facet_counts": [],
"found": 0,
"hits": [],
"out_of": 5,
"page": 1,
"request_params": {
"collection_name": "collection2",
"per_page": 10,
"q": "pizza"
},
"search_cutoff": false,
"search_time_ms": 0
}
]
}Aadarsh
10/10/2023, 5:17 AMHarpreet Sangar
10/10/2023, 5:20 AMif collection=="collection2":
search_request["filter_by"] = "$collection1(code:=name_tag)"
search_request["include_fields"] = "$collection1(*) as collection1"Aadarsh
10/10/2023, 5:37 AMimport typesense
client = typesense.Client(
{
"nodes": [
{
"host": host, # For Typesense Cloud use xxx.a1.typesense.net
"port": port, # For Typesense Cloud use 443
"protocol": protocol, # For Typesense Cloud use https
}
],
"api_key": api_key,
"connection_timeout_seconds": connection_timeout_seconds,
}
)
collection1 = {
"name": "collection1",
"fields": [
{
"name": "name",
"type": "string",
"facet": True,
},
{
"name": "priority",
"type": "int32",
"facet": True,
},
{
"name": "code",
"type": "string",
"facet": True,
},
],
}
document1 = [
{"name": "tags Pizza", "priority": 53, "code": "0"},
{"name": "tags Burger", "priority": 20, "code": "1"},
{"name": "Cake", "priority": 23, "code": "2"},
{"name": "Kiosk", "priority": 72, "code": "3"},
{"name": "Icecream", "priority": 49, "code": "4"},
]
# delete_collection(collection_name=collection1.strip())
# client.collections.create(collection1)
# client.collections["collection1"].documents.import_(document1)
collection2 = {
"name": "collection2",
"fields": [
{
"name": "name",
"type": "string",
"facet": True,
},
{
"name": "priority",
"type": "int32",
"facet": True,
},
{
"name": "code",
"type": "string",
"facet": True,
"reference": "collection1.code",
},
{
"name": "name_tag",
"type": "string[]",
"facet": True,
},
],
}
document2 = [
{"name": "Pizza", "priority": 53, "code": "0", "name_tag": ["0", "1"]},
{"name": "Burger", "priority": 20, "code": "1", "name_tag": ["1"]},
{"name": "Cake", "priority": 23, "code": "2", "name_tag": ["2"]},
{"name": "Kiosk", "priority": 72, "code": "3", "name_tag": ["3"]},
{"name": "Icecream", "priority": 49, "code": "4", "name_tag": ["4"]},
]
# delete_collection(collection_name=collection2.strip())
# client.collections.create(collection2)
# client.collections["collection2"].documents.import_(document2)
def retreive_collection(collection_name, verbose=False):
client.collections[collection_name].retrieve()
if verbose:
print(f'"{collection_name}" retreived successfully')
return
def delete_collection(collection_name, verbose=False):
client.collections[collection_name].delete()
if verbose:
print(f'"{collection_name}" deleted successfully')
return
delete_collection(collection_name="collection1")
client.collections.create(collection1)
client.collections["collection1"].documents.import_(document1)
delete_collection(collection_name="collection2")
client.collections.create(collection2)
client.collections["collection2"].documents.import_(document2)
query = "burger"
collection_names = ["collection1", "collection2"]
filtered_search_requests = list()
for collection in collection_names:
search_request = dict()
search_request["collection"] = collection
search_request["q"] = query
search_request["sort_by"] = "priority:desc,_text_match:desc"
search_request["prioritize_token_position"] = "true"
# if collection=="collection2":
# search_request["filter_by"] = "$collection1(code:=name_tag)"
if collection=="collection2":
search_request["filter_by"] = "$collection1(code:=name_tag)"
search_request["include_fields"] = "$collection1(*) as collection1"
filtered_search_requests.append(search_request)
search_requests = {"searches": filtered_search_requests}
common_search_params = {
"query_by": "name,code",
}
for collection in collection_names:
retreive_collection(collection_name=collection)
response = client.multi_search.perform(search_requests, common_search_params)
print(response)
Response:
{
"results": [
{
"facet_counts": [],
"found": 1,
"hits": [
{
"document": {
"code": "1",
"id": "1",
"name": "tags Burger",
"priority": 20
},
"highlight": {
"name": {
"matched_tokens": [
"Burger"
],
"snippet": "tags <mark>Burger</mark>"
}
},
"highlights": [
{
"field": "name",
"matched_tokens": [
"Burger"
],
"snippet": "tags <mark>Burger</mark>"
}
],
"text_match": 578730123365705900,
"text_match_info": {
"best_field_score": "1108091339005",
"best_field_weight": 15,
"fields_matched": 1,
"score": "578730123365705849",
"tokens_matched": 1
}
}
],
"out_of": 5,
"page": 1,
"request_params": {
"collection_name": "collection1",
"per_page": 10,
"q": "burger"
},
"search_cutoff": false,
"search_time_ms": 0
},
{
"facet_counts": [],
"found": 0,
"hits": [],
"out_of": 5,
"page": 1,
"request_params": {
"collection_name": "collection2",
"per_page": 10,
"q": "burger"
},
"search_cutoff": false,
"search_time_ms": 0
}
]
}Harpreet Sangar
10/10/2023, 5:40 AMname_tag
"$collection1(code:=name_tag)"Harpreet Sangar
10/10/2023, 5:44 AMinclude_by. You can remove the filter_by.Aadarsh
10/10/2023, 5:51 AMname_tag is a string[] field in collection2 that contains all the code from collection1. Basically, I want to get all the codes from collection1 if a result gets matched in collection2. I'm following this structure of documents from this github issue.Harpreet Sangar
10/10/2023, 5:55 AMcollection2 and it has the field name_tag that contains a list of code on the basis of which you want to include the related document of collection1 that has the same code.Aadarsh
10/10/2023, 5:57 AMHarpreet Sangar
10/10/2023, 5:58 AMit should search through all the collections that are retreived.I didn't understand this part
Aadarsh
10/10/2023, 6:00 AMclient.collections[collection_name].retrieve() I'm retreiving all the collections in the code above to search in those for the text matchesAadarsh
10/10/2023, 7:25 AMHarpreet Sangar
10/10/2023, 7:34 AMcollection2 document, you'll have to create a junction collection with the following schema:
{
"name": "code_links",
"fields": [
{
"name": "coll1",
"type": "string",
"reference": "collection1.code",
},
{
"name": "coll2",
"type": "string",
"reference": "collection2.id",
}
],
}
coll1 field will store the code value and coll2 field will store the document id of the collection2 document. We have to use this approach since there are multiple reference values in each doc.Harpreet Sangar
10/10/2023, 7:36 AMcollection2 now. The search would look like:
if collection=="collection2":
search_request["filter_by"] = "$code_links(id:*)",
search_request["include_fields"] = "$collection1(*) as collection1"Harpreet Sangar
10/10/2023, 7:39 AMstring[] field as reference too so you won't have to create an extra collection for this use case. I'll let you know.Aadarsh
10/10/2023, 7:53 AMtypesense.exceptions.RequestMalformed: [Errno 400] One or more search parameters are malformed.Harpreet Sangar
10/10/2023, 7:55 AMsearch_request code snippet?Aadarsh
10/10/2023, 7:59 AMAadarsh
10/10/2023, 8:01 AMsearch_request: {'collection': 'collection2', 'q': 'pizza', 'sort_by': 'priority:desc,_text_match:desc', 'prioritize_token_position': 'true', 'filter_by': '$code_links(id:*)', 'include_fields': '$collection1(*) as collection1'}
Response:
{
"results": [
{
"facet_counts": [],
"found": 1,
"hits": [
{
"document": {
"code": "0",
"id": "0",
"name": "tags Pizza",
"priority": 53
},
"highlight": {
"name": {
"matched_tokens": [
"Pizza"
],
"snippet": "tags <mark>Pizza</mark>"
}
},
"highlights": [
{
"field": "name",
"matched_tokens": [
"Pizza"
],
"snippet": "tags <mark>Pizza</mark>"
}
],
"text_match": 578730123365705900,
"text_match_info": {
"best_field_score": "1108091339005",
"best_field_weight": 15,
"fields_matched": 1,
"score": "578730123365705849",
"tokens_matched": 1
}
}
],
"out_of": 5,
"page": 1,
"request_params": {
"collection_name": "collection1",
"per_page": 10,
"q": "pizza"
},
"search_cutoff": false,
"search_time_ms": 0
},
{
"code": 400,
"error": "Failed to join on `code_links`: No reference field found."
}
]
}Harpreet Sangar
10/10/2023, 8:11 AMcollection1 = {
"name": "collection1",
"fields": [
{
"name": "name",
"type": "string",
"facet": True,
},
{
"name": "priority",
"type": "int32",
"facet": True,
},
{
"name": "code",
"type": "string",
"facet": True,
},
],
}
document1 = [
{"name": "tags Pizza", "priority": 53, "code": "0"},
{"name": "tags Burger", "priority": 20, "code": "1"},
{"name": "Cake", "priority": 23, "code": "2"},
{"name": "Kiosk", "priority": 72, "code": "3"},
{"name": "Icecream", "priority": 49, "code": "4"},
]
# delete_collection(collection_name=collection1.strip())
# client.collections.create(collection1)
# client.collections["collection1"].documents.import_(document1)
collection2 = {
"name": "collection2",
"fields": [
{
"name": "name",
"type": "string",
"facet": True,
},
{
"name": "priority",
"type": "int32",
"facet": True,
},
{
"name": "code",
"type": "string",
"facet": True,
"reference": "collection1.code",
},
{
"name": "name_tag",
"type": "string[]",
"facet": True,
},
],
}
document2 = [
{"name": "Pizza", "priority": 53, "code": "0", "name_tag": ["0", "1"]},
{"name": "Burger", "priority": 20, "code": "1", "name_tag": ["1"]},
{"name": "Cake", "priority": 23, "code": "2", "name_tag": ["2"]},
{"name": "Kiosk", "priority": 72, "code": "3", "name_tag": ["3"]},
{"name": "Icecream", "priority": 49, "code": "4", "name_tag": ["4"]},
]
# delete_collection(collection_name=collection2.strip())
# client.collections.create(collection2)
# client.collections["collection2"].documents.import_(document2)
code_links = {
"name": "code_links",
"fields": [
{
"name": "coll1",
"type": "string",
"reference": "collection1.code",
},
{
"name": "coll2",
"type": "string",
"reference": "collection2.id",
}
],
}
documents = [
{"coll1": "0", "coll2": "0"},
{"coll1": "1", "coll2": "0"},
{"coll1": "1", "coll2": "1"},
{"coll1": "2", "coll2": "2"},
{"coll1": "3", "coll2": "3"},
{"coll1": "4", "coll2": "4"}
]
def retreive_collection(collection_name, verbose=False):
client.collections[collection_name].retrieve()
if verbose:
print(f'"{collection_name}" retreived successfully')
return
def delete_collection(collection_name, verbose=False):
client.collections[collection_name].delete()
if verbose:
print(f'"{collection_name}" deleted successfully')
return
delete_collection(collection_name="collection1")
client.collections.create(collection1)
client.collections["collection1"].documents.import_(document1)
delete_collection(collection_name="collection2")
client.collections.create(collection2)
client.collections["collection2"].documents.import_(document2)
delete_collection(collection_name="code_links")
client.collections.create(code_links)
client.collections["code_links"].documents.import_(documents)
query = "burger"
collection_names = ["collection1", "collection2"]
filtered_search_requests = list()
for collection in collection_names:
search_request = dict()
search_request["collection"] = collection
search_request["q"] = query
search_request["sort_by"] = "priority:desc,_text_match:desc"
search_request["prioritize_token_position"] = "true"
# if collection=="collection2":
# search_request["filter_by"] = "$collection1(code:=name_tag)"
if collection=="collection2":
search_request["filter_by"] = "$code_links(id:*)"
search_request["include_fields"] = "$collection1(*) as collection1"
filtered_search_requests.append(search_request)
search_requests = {"searches": filtered_search_requests}
common_search_params = {
"query_by": "name,code",
}
for collection in collection_names:
retreive_collection(collection_name=collection)
response = client.multi_search.perform(search_requests, common_search_params)
print(response)Aadarsh
10/10/2023, 8:20 AMpizza , shouldn't Collection2 Response contain tags Burger as well rather than just the name_tag array?
{
"results": [
{
"facet_counts": [],
"found": 1,
"hits": [
{
"document": {
"code": "0",
"id": "0",
"name": "tags Pizza",
"priority": 53
},
"highlight": {
"name": {
"matched_tokens": [
"Pizza"
],
"snippet": "tags <mark>Pizza</mark>"
}
},
"highlights": [
{
"field": "name",
"matched_tokens": [
"Pizza"
],
"snippet": "tags <mark>Pizza</mark>"
}
],
"text_match": 578730123365705900,
"text_match_info": {
"best_field_score": "1108091339005",
"best_field_weight": 15,
"fields_matched": 1,
"score": "578730123365705849",
"tokens_matched": 1
}
}
],
"out_of": 5,
"page": 1,
"request_params": {
"collection_name": "collection1",
"per_page": 10,
"q": "pizza"
},
"search_cutoff": false,
"search_time_ms": 0
},
{
"facet_counts": [],
"found": 1,
"hits": [
{
"document": {
"code": "0",
"code_sequence_id": 0,
"coll1": [
"0",
"1"
],
"coll1_sequence_id": [
0,
1
],
"coll2": [
"0",
"0"
],
"coll2_sequence_id": [
0,
0
],
"collection1.code": "0",
"collection1.name": "tags Pizza",
"collection1.priority": 53,
"id": "0",
"name": "Pizza",
"name_tag": [
"0",
"1"
],
"priority": 53
},
"highlight": {
"name": {
"matched_tokens": [
"Pizza"
],
"snippet": "<mark>Pizza</mark>"
}
},
"highlights": [
{
"field": "name",
"matched_tokens": [
"Pizza"
],
"snippet": "<mark>Pizza</mark>"
}
],
"text_match": 578730123366232200,
"text_match_info": {
"best_field_score": "1108091339262",
"best_field_weight": 15,
"fields_matched": 1,
"score": "578730123366232185",
"tokens_matched": 1
}
}
],
"out_of": 5,
"page": 1,
"request_params": {
"collection_name": "collection2",
"per_page": 10,
"q": "pizza"
},
"search_cutoff": false,
"search_time_ms": 0
}
]
}Aadarsh
10/10/2023, 8:23 AMtags Burger to tags Pizzeria in collection1 but it doesn't show up in the response as matched with the query pizzaHarpreet Sangar
10/10/2023, 9:05 AMexport TYPESENSE_API_KEY=abcd
curl -H "X-TYPESENSE-API-KEY: ${TYPESENSE_API_KEY}" \
-X DELETE \
"http://localhost:8108/collections/collection1"
curl -H "X-TYPESENSE-API-KEY: ${TYPESENSE_API_KEY}" \
-X DELETE \
"http://localhost:8108/collections/collection2"
curl -H "X-TYPESENSE-API-KEY: ${TYPESENSE_API_KEY}" \
-X DELETE \
"http://localhost:8108/collections/code_links"
curl "http://localhost:8108/collections" \
-X POST \
-H "Content-Type: application/json" \
-H "X-TYPESENSE-API-KEY: ${TYPESENSE_API_KEY}" \
-d '{
"name": "collection1",
"fields": [
{"name": "name", "type": "string", "facet": true},
{"name": "priority", "type": "int32", "facet": true},
{"name": "code", "type": "string", "facet": true}
]
}'
curl "http://localhost:8108/collections/collection1/documents/import?action=create" \
-H "X-TYPESENSE-API-KEY: ${TYPESENSE_API_KEY}" \
-H "Content-Type: text/plain" \
-X POST \
-d '{"name": "tags Pizza", "priority": 53, "code": "0"}
{"name": "tags Burger", "priority": 20, "code": "1"}
{"name": "Cake", "priority": 23, "code": "2"}
{"name": "Kiosk", "priority": 72, "code": "3"}
{"name": "Icecream", "priority": 49, "code": "4"}'
curl "http://localhost:8108/collections" \
-X POST \
-H "Content-Type: application/json" \
-H "X-TYPESENSE-API-KEY: ${TYPESENSE_API_KEY}" \
-d '{
"name": "collection2",
"fields": [
{"name": "name", "type": "string", "facet": true},
{"name": "priority", "type": "int32", "facet": true},
{"name": "name_tag", "type": "string[]", "facet": true}
]
}'
curl "http://localhost:8108/collections/collection2/documents/import?action=create" \
-H "X-TYPESENSE-API-KEY: ${TYPESENSE_API_KEY}" \
-H "Content-Type: text/plain" \
-X POST \
-d '{"name": "Pizza", "priority": 53, "name_tag": ["0", "1"]}
{"name": "Burger", "priority": 20, "name_tag": ["1"]}
{"name": "Cake", "priority": 23, "name_tag": ["2"]}
{"name": "Kiosk", "priority": 72, "name_tag": ["3"]}
{"name": "Icecream", "priority": 49, "name_tag": ["4"]}'
curl "http://localhost:8108/collections" \
-X POST \
-H "Content-Type: application/json" \
-H "X-TYPESENSE-API-KEY: ${TYPESENSE_API_KEY}" \
-d '{
"name": "code_links",
"fields": [
{"name": "coll1", "type": "string", "reference": "collection1.code"},
{"name": "coll2", "type": "string", "reference": "collection2.id"}
]
}'
curl "http://localhost:8108/collections/code_links/documents/import?action=create" \
-H "X-TYPESENSE-API-KEY: ${TYPESENSE_API_KEY}" \
-H "Content-Type: text/plain" \
-X POST \
-d '{"coll1": "0", "coll2": "0"}
{"coll1": "1", "coll2": "0"}
{"coll1": "1", "coll2": "1"}
{"coll1": "2", "coll2": "2"}
{"coll1": "3", "coll2": "3"}
{"coll1": "4", "coll2": "4"}'
curl 'http://localhost:8108/multi_search' -X POST -H "X-TYPESENSE-API-KEY: ${TYPESENSE_API_KEY}" -d '
{"searches":[
{
"collection":"collection2",
"q":"pizza",
"query_by": "name",
"filter_by":"$code_links(id:*)",
"include_fields": "$collection1(*) as collection1",
"exclude_fields": "$code_links(*)"
}
]}' | jq
I get following response
"hits": [
{
"document": {
"collection1.code": [
"0",
"1"
],
"collection1.name": [
"tags Pizza",
"tags Burger"
],
"collection1.priority": [
53,
20
],
"id": "0",
"name": "Pizza",
"name_tag": [
"0",
"1"
],
"priority": 53
},
"highlight": {
"name": {
"matched_tokens": [
"Pizza"
],
"snippet": "<mark>Pizza</mark>"
}
},
"highlights": [
{
"field": "name",
"matched_tokens": [
"Pizza"
],
"snippet": "<mark>Pizza</mark>"
}
],
"text_match": 578730123365712000,
"text_match_info": {
"best_field_score": "1108091339008",
"best_field_weight": 15,
"fields_matched": 1,
"score": "578730123365711993",
"tokens_matched": 1
}
}Aadarsh
10/10/2023, 9:10 AMAadarsh
10/10/2023, 9:11 AMHarpreet Sangar
10/10/2023, 9:11 AMAadarsh
10/10/2023, 9:22 AM0.26.0.rc22 branch?Harpreet Sangar
10/10/2023, 9:23 AMAadarsh
10/10/2023, 9:23 AMHarpreet Sangar
10/10/2023, 9:24 AMKishore Nallan
10/10/2023, 9:31 AMAadarsh
10/10/2023, 9:32 AMcode_links) for efficiency soon. Thanks a lot!Kishore Nallan
10/10/2023, 9:33 AMAadarsh
10/10/2023, 9:34 AMAadarsh
10/19/2023, 6:30 AMimport typesense
client = typesense.Client(
{
"nodes": [
{
"host": host, # For Typesense Cloud use xxx.a1.typesense.net
"port": port, # For Typesense Cloud use 443
"protocol": protocol, # For Typesense Cloud use https
}
],
"api_key": api_key,
"connection_timeout_seconds": connection_timeout_seconds,
}
)
collection1 = {
"name": "collection1", ## tags
"fields": [
{
"name": "name",
"type": "string",
"facet": True,
},
{
"name": "priority",
"type": "int32",
"facet": True,
},
{
"name": "code",
"type": "string",
"facet": True,
},
],
}
document1 = [
{"name": "tags Pizza", "priority": 53, "code": "3"},
{"name": "tags Pizzeria", "priority": 20, "code": "1"},
{"name": "Cake", "priority": 23, "code": "2"},
{"name": "Kiosk", "priority": 72, "code": "3"},
{"name": "Icecream", "priority": 49, "code": "4"},
]
collection2 = {
"name": "collection2", # items
"fields": [
{
"name": "name",
"type": "string",
"facet": True,
},
{
"name": "priority",
"type": "int32",
"facet": True,
},
{
"name": "code",
"type": "string",
"facet": True,
},
{
"name": "reference_collection_id",
"type": "string",
"facet": True,
"reference": "collection1.code",
},
],
}
document2 = [
{"name": "Pizza", "priority": 53, "code": "0", "reference_collection_id": "0"},
{"name": "Burger", "priority": 20, "code": "1", "reference_collection_id": "1"},
{"name": "Cake", "priority": 23, "code": "2", "reference_collection_id": "2"},
{"name": "Kiosk", "priority": 72, "code": "3", "reference_collection_id": "3"},
{"name": "Icecream", "priority": 49, "code": "4", "reference_collection_id": "4"},
]
code_links = {
"name": "code_links",
"fields": [
{
"name": "coll1",
"type": "string",
"reference": "collection1.code",
},
{
"name": "coll2",
"type": "string",
"reference": "collection2.id",
}
],
}
documents = [
{"coll1": "0", "coll2": "0"},
{"coll1": "1", "coll2": "1"},
{"coll1": "2", "coll2": "2"},
{"coll1": "3", "coll2": "3"},
{"coll1": "4", "coll2": "4"}
]
def retreive_collection(collection_name, verbose=False):
client.collections[collection_name].retrieve()
if verbose:
print(f'"{collection_name}" retreived successfully')
return
def delete_collection(collection_name, verbose=False):
client.collections[collection_name].delete()
if verbose:
print(f'"{collection_name}" deleted successfully')
return
delete_collection(collection_name="collection1")
client.collections.create(collection1)
client.collections["collection1"].documents.import_(document1)
delete_collection(collection_name="collection2")
client.collections.create(collection2)
client.collections["collection2"].documents.import_(document2)
delete_collection(collection_name="code_links")
client.collections.create(code_links)
client.collections["code_links"].documents.import_(documents)
query = "kiosk"
collection_names = ["collection1", "collection2"]
filtered_search_requests = list()
for collection in collection_names:
search_request = dict()
search_request["collection"] = collection
search_request["q"] = query
search_request["sort_by"] = "priority:desc,_text_match:desc"
search_request["prioritize_token_position"] = "true"
if collection=="collection2":
search_request["filter_by"] = "$code_links(id:*)"
search_request["include_fields"] = "$collection1(*) as collection1"
search_request["exclude_fields"] = "$code_links(*)"
filtered_search_requests.append(search_request)
search_requests = {"searches": filtered_search_requests}
common_search_params = {
"query_by": "name,code",
}
for collection in collection_names:
retreive_collection(collection_name=collection)
response = client.multi_search.perform(search_requests, common_search_params)
print(response)
search_request = {'collection': 'collection2', 'q': 'kiosk', 'sort_by': 'priority:desc,_text_match:desc', 'prioritize_token_position': 'true', 'filter_by': '$code_links(id:*)', 'include_fields': '$collection1(*) as collection1', 'exclude_fields': '$code_links(*)'}
Response:
{
"results": [
{
"facet_counts": [],
"found": 1,
"hits": [
{
"document": {
"code": "3",
"id": "3",
"name": "Kiosk",
"priority": 72
},
"highlight": {
"name": {
"matched_tokens": [
"Kiosk"
],
"snippet": "markKiosk/mark"
}
},
"highlights": [
{
"field": "name",
"matched_tokens": [
"Kiosk"
],
"snippet": "markKiosk/mark"
}
],
"text_match": 578730123366232200,
"text_match_info": {
"best_field_score": "1108091339262",
"best_field_weight": 15,
"fields_matched": 1,
"score": "578730123366232185",
"tokens_matched": 1
}
}
],
"out_of": 5,
"page": 1,
"request_params": {
"collection_name": "collection1",
"per_page": 10,
"q": "kiosk"
},
"search_cutoff": false,
"search_time_ms": 0
},
{
"facet_counts": [],
"found": 0,
"hits": [],
"out_of": 3,
"page": 1,
"request_params": {
"collection_name": "collection2",
"per_page": 10,
"q": "kiosk"
},
"search_cutoff": false,
"search_time_ms": 0
}
]
}
Here, as I searched for kiosk it should have searched within the collection2 as well with references to collection1. Please let me know the correct way to do this.
I'm using typesense/typesense:0.26.0.rc24Harpreet Sangar
10/19/2023, 6:35 AMcollection2 be collection2.reference_collection_id ?
code_links = {
"name": "code_links",
"fields": [
{
"name": "coll1",
"type": "string",
"reference": "collection1.code",
},
{
"name": "coll2",
"type": "string",
"reference": "collection2.reference_collection_id", # here
}
],
}Aadarsh
10/19/2023, 6:36 AMAadarsh
10/19/2023, 6:38 AMcode_links if we have single IDs to refer and not array as earlier?Harpreet Sangar
10/19/2023, 6:41 AMIt does not change the responseI think it's because of this in
collection2
{
"name": "reference_collection_id",
"type": "string",
"facet": True,
"reference": "collection1.code",
},
Also, why do we need to introduce a middleware collectionThat's right you don't needif we have single IDs to refer and not array as earlier?code_links
code_links collection in this scenarioHarpreet Sangar
10/19/2023, 6:42 AMcollection2 and the following search request
if collection=="collection2":
search_request["include_fields"] = "$collection1(*) as collection1"Harpreet Sangar
10/19/2023, 6:44 AMfilter_by since you are searching the collection that already has reference to collection1Aadarsh
10/19/2023, 6:47 AMAadarsh
10/19/2023, 9:37 AMimport typesense
client = typesense.Client(
{
"nodes": [
{
"host": host, # For Typesense Cloud use xxx.a1.typesense.net
"port": port, # For Typesense Cloud use 443
"protocol": protocol, # For Typesense Cloud use https
}
],
"api_key": api_key,
"connection_timeout_seconds": connection_timeout_seconds,
}
)
collection1 = {
"name": "collection1", ## tags
"fields": [
{
"name": "name",
"type": "string",
"facet": True,
},
{
"name": "priority",
"type": "int32",
"facet": True,
},
{
"name": "code",
"type": "string",
"facet": True,
},
],
}
document1 = [
{"name": "tags Pizza", "priority": 53, "code": "3"},
{"name": "tags Pizzeria", "priority": 20, "code": "1"},
{"name": "Cake", "priority": 23, "code": "2"},
{"name": "Kiosk", "priority": 72, "code": "3"},
{"name": "Icecream", "priority": 49, "code": "4"},
]
collection2 = {
"name": "collection2", # items
"fields": [
{
"name": "name",
"type": "string",
"facet": True,
},
{
"name": "priority",
"type": "int32",
"facet": True,
},
{
"name": "code",
"type": "string",
"facet": True,
},
{
"name": "reference_collection_id",
"type": "string",
"facet": True,
"reference": "collection1.code",
},
],
}
document2 = [
{"name": "Pizza", "priority": 53, "code": "0", "reference_collection_id": "10101010"}, ## random number not in collection1.code
{"name": "Burger", "priority": 20, "code": "1", "reference_collection_id": "10101010"},
{"name": "Cake", "priority": 23, "code": "2", "reference_collection_id": "10101010"},
{"name": "Kiosk", "priority": 72, "code": "3", "reference_collection_id": "3"}, ## code there in collection1
{"name": "Icecream", "priority": 49, "code": "4", "reference_collection_id": "10101010"},
]
def retreive_collection(collection_name, verbose=False):
client.collections[collection_name].retrieve()
if verbose:
print(f'"{collection_name}" retreived successfully')
return
def delete_collection(collection_name, verbose=False):
client.collections[collection_name].delete()
if verbose:
print(f'"{collection_name}" deleted successfully')
return
delete_collection(collection_name="collection1")
client.collections.create(collection1)
client.collections["collection1"].documents.import_(document1)
delete_collection(collection_name="collection2")
client.collections.create(collection2)
client.collections["collection2"].documents.import_(document2)
query = "kiosk"
collection_names = ["collection1", "collection2"]
filtered_search_requests = list()
for collection in collection_names:
search_request = dict()
search_request["collection"] = collection
search_request["q"] = query
search_request["sort_by"] = "priority:desc,_text_match:desc"
search_request["prioritize_token_position"] = "true"
if collection=="collection2":
search_request["include_fields"] = "$collection1(*) as collection1"
filtered_search_requests.append(search_request)
search_requests = {"searches": filtered_search_requests}
print("search_request =", search_requests)
common_search_params = {
"query_by": "name,code",
}
for collection in collection_names:
retreive_collection(collection_name=collection)
response = client.multi_search.perform(search_requests, common_search_params)
print(response)
search_request = {'searches': [{'collection': 'collection1', 'q': 'kiosk', 'sort_by': 'priority:desc,_text_match:desc', 'prioritize_token_position': 'true'}, {'collection': 'collection2', 'q': 'kiosk', 'sort_by': 'priority:desc,_text_match:desc', 'prioritize_token_position': 'true', 'include_fields': '$collection1(*) as collection1'}]}
Response:
{
"results": [
{
"facet_counts": [],
"found": 1,
"hits": [
{
"document": {
"code": "3",
"id": "3",
"name": "Kiosk",
"priority": 72
},
"highlight": {
"name": {
"matched_tokens": [
"Kiosk"
],
"snippet": "<mark>Kiosk</mark>"
}
},
"highlights": [
{
"field": "name",
"matched_tokens": [
"Kiosk"
],
"snippet": "<mark>Kiosk</mark>"
}
],
"text_match": 578730123366232200,
"text_match_info": {
"best_field_score": "1108091339262",
"best_field_weight": 15,
"fields_matched": 1,
"score": "578730123366232185",
"tokens_matched": 1
}
}
],
"out_of": 5,
"page": 1,
"request_params": {
"collection_name": "collection1",
"per_page": 10,
"q": "kiosk"
},
"search_cutoff": false,
"search_time_ms": 0
},
{
"facet_counts": [],
"found": 0,
"hits": [],
"out_of": 0,
"page": 1,
"request_params": {
"collection_name": "collection2",
"per_page": 10,
"q": "kiosk"
},
"search_cutoff": false,
"search_time_ms": 0
}
]
}Harpreet Sangar
10/19/2023, 9:40 AM"out_of": 0, is returned. No documents have been indexed.Harpreet Sangar
10/19/2023, 9:41 AMcollection2 have the same non-existent reference.Aadarsh
10/19/2023, 10:00 AM{"name": "Kiosk", "priority": 72, "code": "3", "reference_collection_id": "3"}, ## code there in collection1
Document2 has this row having correct reference... Please explainHarpreet Sangar
10/19/2023, 10:02 AMAadarsh
10/19/2023, 10:03 AMHarpreet Sangar
10/19/2023, 10:05 AMAadarsh
10/19/2023, 10:08 AMdocument2 and there's no new response after the above addressed issue.Aadarsh
10/19/2023, 10:09 AMdocument2 has one correct reference, why does the response still return "out_of" : 0?Harpreet Sangar
10/19/2023, 10:10 AMThis indicates there are no documents in theis returned. No documents have been indexed."out_of": 0,
collection2.Aadarsh
10/19/2023, 10:13 AMreference_collection_id then the document2 gets indexed and search works properly without referencing. This also works when I add the reference_collection_id with correct reference IDs. But, as soon as I add the field with even one incorrect reference ID, the document doesn't get indexed. Am I declaring the document incorrectly?Harpreet Sangar
10/19/2023, 10:16 AMdocument2 = [
{"name": "Kiosk", "priority": 72, "code": "3", "reference_collection_id": "3"}, ## code there in collection1
{"name": "Pizza", "priority": 53, "code": "0", "reference_collection_id": "10101010"}, ## random number not in collection1.code
{"name": "Burger", "priority": 20, "code": "1", "reference_collection_id": "10101010"},
{"name": "Cake", "priority": 23, "code": "2", "reference_collection_id": "10101010"},
{"name": "Icecream", "priority": 49, "code": "4", "reference_collection_id": "10101010"},
]Aadarsh
10/19/2023, 10:18 AM"out_of": 0Harpreet Sangar
10/19/2023, 10:18 AMAadarsh
10/19/2023, 10:18 AMHarpreet Sangar
10/19/2023, 12:52 PMprint(client.collections["collection2"].documents.import_(document2))Aadarsh
10/20/2023, 1:09 PM[{'code': 400, 'document': '{"name": "Kiosk", "priority": 72, "code": "3", "reference_collection_id": "3"}', 'error': 'Multiple documents having `code: 3` found in the collection `collection1`.', 'success': False}, {'code': 400, 'document': '{"name": "Pizza", "priority": 53, "code": "0", "reference_collection_id": "10101010"}', 'error': 'Referenced document having `code: 10101010` not found in the collection `collection1`.', 'success': False}, {'code': 400, 'document': '{"name": "Burger", "priority": 20, "code": "1", "reference_collection_id": "10101010"}', 'error': 'Referenced document having `code: 10101010` not found in the collection `collection1`.', 'success': False}, {'code': 400, 'document': '{"name": "Cake", "priority": 23, "code": "2", "reference_collection_id": "10101010"}', 'error': 'Referenced document having `code: 10101010` not found in the collection `collection1`.', 'success': False}, {'code': 400, 'document': '{"name": "Icecream", "priority": 49, "code": "4", "reference_collection_id": "10101010"}', 'error': 'Referenced document having `code: 10101010` not found in the collection `collection1`.', 'success': False}]Harpreet Sangar
10/20/2023, 1:11 PMMultiple documents having `code: 3` found in the collection `collection1`Harpreet Sangar
10/20/2023, 1:12 PMcode: 3 is not a unique value in collection1Aadarsh
10/20/2023, 1:14 PMdocument1 = [
{"name": "tags Pizza", "priority": 53, "code": "0"},
{"name": "tags Pizzeria", "priority": 20, "code": "1"},
{"name": "Cake", "priority": 23, "code": "2"},
{"name": "Kiosk", "priority": 72, "code": "3"},
{"name": "Icecream", "priority": 49, "code": "4"},
]
And there's still no hits in collection2Harpreet Sangar
10/20/2023, 1:14 PMout_of is still 0 ?Aadarsh
10/20/2023, 1:14 PM"out_of": 1Harpreet Sangar
10/20/2023, 1:14 PMAadarsh
10/20/2023, 1:15 PMkioskHarpreet Sangar
10/20/2023, 1:15 PMcollection2Aadarsh
10/20/2023, 1:18 PMAadarsh
10/23/2023, 2:41 PMstring[]) of collection2 and the other field has a single ID (string) to refer in some other collection3. I have created a mid collection code_links as we figured out. I get "out_of": 0 in the response as I'd need to use filter_by to refer collection2 and should avoid using filter_by to refer collection3. Can you suggest a way to handle this?Harpreet Sangar
10/24/2023, 3:33 AMThis indicates that no document is present in the collection. You should check the response of the import API to see why no document was indexed. Also, I've added the ability to have a"out_of": 0
reference in an array type field so you won't have to create code_links collection.Harpreet Sangar
10/24/2023, 3:48 AMI'd need to useThe suggestion regarding not needing theto refer collection2 and should avoid usingfilter_byto refer collection3filter_by
filter_by expression in your second case was just meant for the scenario where you're searching the collection that has the reference field (collection1) and you only need to include the fields of the referenced documents. You still can have any filter_by expression. If for example, you wanted to filter by a field in the collection3, you can specify $collection3(field_name:value).Aadarsh
10/24/2023, 3:54 AMHarpreet Sangar
10/24/2023, 3:58 AMAadarsh
10/24/2023, 4:00 AMKishore Nallan
10/24/2023, 4:02 AMAadarsh
10/25/2023, 11:47 AM"include_fields" to include all fields from two different collections? I have a collection like this:
collection2 = {
"name": "collection2",
"fields": [
{
"name": "name",
"type": "string",
"facet": True,
},
{
"name": "priority",
"type": "int32",
"facet": True,
},
{
"name": "code",
"type": "string",
"facet": True,
},
{
"name": "name_tag",
"type": "string[]",
"facet": True,
"reference": "collection1.code",
},
{
"name": "coll3_ref",
"type": "string",
"facet": True,
"reference": "collection3.code",
},
],
}Kishore Nallan
10/25/2023, 11:48 AM$collection1(*) to fetch all fields from collection1Aadarsh
10/25/2023, 12:22 PMcollection1 and collection3Kishore Nallan
10/25/2023, 12:23 PMAadarsh
10/25/2023, 12:41 PMsearch_requests = {'searches': [{'collection': 'collection1', 'q': 'kiosk', 'sort_by': 'priority:desc,_text_match:desc', 'prioritize_token_position': 'true'}, {'collection': 'collection2', 'q': 'kiosk', 'sort_by': 'priority:desc,_text_match:desc', 'prioritize_token_position': 'true', 'include_fields': '$collection1(*),$collection3(*)'}, {'collection': 'collection3', 'q': 'kiosk', 'sort_by': 'priority:desc,_text_match:desc', 'prioritize_token_position': 'true'}]}Kishore Nallan
10/25/2023, 12:42 PMAadarsh
10/25/2023, 12:43 PMclient.multi_search.perform(search_requests, common_search_params) gets stuckHarpreet Sangar
10/25/2023, 1:12 PM{'collection': 'collection2', 'q': '*'}Aadarsh
10/25/2023, 2:27 PMsearch_requests = {'searches': [{'collection': 'collection2', 'q': '*'}]}
{
"results": [
{
"facet_counts": [],
"found": 1,
"hits": [
{
"document": {
"code": "3",
"id": "0",
"name": "Kiosk",
"name_tag": [
"0",
"1"
],
"name_tag_sequence_id": [
0,
1
],
"priority": 72,
"reference_collection_id": "0",
"reference_collection_id_sequence_id": 0
},
"highlight": {},
"highlights": []
}
],
"out_of": 1,
"page": 1,
"request_params": {
"collection_name": "collection2",
"per_page": 10,
"q": "*"
},
"search_cutoff": false,
"search_time_ms": 0
}
]
}Harpreet Sangar
10/25/2023, 2:29 PM{'collection': 'collection1', 'q': '*'},
{'collection': 'collection3', 'q': '*'}Aadarsh
10/25/2023, 2:31 PMsearch_requests = {'searches': [{'collection': 'collection1', 'q': '*'}, {'collection': 'collection3', 'q': '*'}]}
{
"results": [
{
"facet_counts": [],
"found": 5,
"hits": [
{
"document": {
"code": "4",
"id": "4",
"name": "Icecream",
"priority": 49
},
"highlight": {},
"highlights": []
},
{
"document": {
"code": "3",
"id": "3",
"name": "Kiosk",
"priority": 72
},
"highlight": {},
"highlights": []
},
{
"document": {
"code": "2",
"id": "2",
"name": "Cake",
"priority": 23
},
"highlight": {},
"highlights": []
},
{
"document": {
"code": "1",
"id": "1",
"name": "tags Pizzeria",
"priority": 20
},
"highlight": {},
"highlights": []
},
{
"document": {
"code": "0",
"id": "0",
"name": "tags Pizza",
"priority": 53
},
"highlight": {},
"highlights": []
}
],
"out_of": 5,
"page": 1,
"request_params": {
"collection_name": "collection1",
"per_page": 10,
"q": "*"
},
"search_cutoff": false,
"search_time_ms": 0
},
{
"facet_counts": [],
"found": 5,
"hits": [
{
"document": {
"code": "4",
"id": "4",
"name": "Icecream",
"priority": 49
},
"highlight": {},
"highlights": []
},
{
"document": {
"code": "3",
"id": "3",
"name": "Kiosk",
"priority": 72
},
"highlight": {},
"highlights": []
},
{
"document": {
"code": "2",
"id": "2",
"name": "Cake",
"priority": 23
},
"highlight": {},
"highlights": []
},
{
"document": {
"code": "1",
"id": "1",
"name": "coll3 Pizzeria",
"priority": 20
},
"highlight": {},
"highlights": []
},
{
"document": {
"code": "0",
"id": "0",
"name": "coll3 Pizza",
"priority": 53
},
"highlight": {},
"highlights": []
}
],
"out_of": 5,
"page": 1,
"request_params": {
"collection_name": "collection3",
"per_page": 10,
"q": "*"
},
"search_cutoff": false,
"search_time_ms": 0
}
]
}Harpreet Sangar
10/25/2023, 2:34 PMHarpreet Sangar
10/25/2023, 2:43 PMAadarsh
10/25/2023, 3:26 PM$collection1(*)Aadarsh
10/25/2023, 3:30 PM$collection3(*) (the string type reference)
search_requests = {'searches': [{'collection': 'collection1', 'q': '*', 'sort_by': 'priority:desc,_text_match:desc', 'prioritize_token_position': 'true'}, {'collection': 'collection2', 'q': '*', 'sort_by': 'priority:desc,_text_match:desc', 'prioritize_token_position': 'true', 'include_fields': '$collection3(*)'}, {'collection': 'collection3', 'q': '*', 'sort_by': 'priority:desc,_text_match:desc', 'prioritize_token_position': 'true'}]}
{
"results": [
{
"facet_counts": [],
"found": 5,
"hits": [
{
"document": {
"code": "3",
"id": "3",
"name": "Kiosk",
"priority": 72
},
"highlight": {},
"highlights": [],
"text_match": 100,
"text_match_info": {
"best_field_score": "0",
"best_field_weight": 12,
"fields_matched": 4,
"score": "100",
"tokens_matched": 0
}
},
{
"document": {
"code": "0",
"id": "0",
"name": "tags Pizza",
"priority": 53
},
"highlight": {},
"highlights": [],
"text_match": 100,
"text_match_info": {
"best_field_score": "0",
"best_field_weight": 12,
"fields_matched": 4,
"score": "100",
"tokens_matched": 0
}
},
{
"document": {
"code": "4",
"id": "4",
"name": "Icecream",
"priority": 49
},
"highlight": {},
"highlights": [],
"text_match": 100,
"text_match_info": {
"best_field_score": "0",
"best_field_weight": 12,
"fields_matched": 4,
"score": "100",
"tokens_matched": 0
}
},
{
"document": {
"code": "2",
"id": "2",
"name": "Cake",
"priority": 23
},
"highlight": {},
"highlights": [],
"text_match": 100,
"text_match_info": {
"best_field_score": "0",
"best_field_weight": 12,
"fields_matched": 4,
"score": "100",
"tokens_matched": 0
}
},
{
"document": {
"code": "1",
"id": "1",
"name": "tags Pizzeria",
"priority": 20
},
"highlight": {},
"highlights": [],
"text_match": 100,
"text_match_info": {
"best_field_score": "0",
"best_field_weight": 12,
"fields_matched": 4,
"score": "100",
"tokens_matched": 0
}
}
],
"out_of": 5,
"page": 1,
"request_params": {
"collection_name": "collection1",
"per_page": 10,
"q": "*"
},
"search_cutoff": false,
"search_time_ms": 0
},
{
"facet_counts": [],
"found": 1,
"hits": [
{
"document": {
"code": "0",
"id": "0",
"name": "coll3 Pizza",
"name_tag": [
"0",
"1"
],
"name_tag_sequence_id": [
0,
1
],
"priority": 53,
"reference_collection_id": "0",
"reference_collection_id_sequence_id": 0
},
"highlight": {},
"highlights": [],
"text_match": 100,
"text_match_info": {
"best_field_score": "0",
"best_field_weight": 12,
"fields_matched": 4,
"score": "100",
"tokens_matched": 0
}
}
],
"out_of": 1,
"page": 1,
"request_params": {
"collection_name": "collection2",
"per_page": 10,
"q": "*"
},
"search_cutoff": false,
"search_time_ms": 0
},
{
"facet_counts": [],
"found": 5,
"hits": [
{
"document": {
"code": "3",
"id": "3",
"name": "Kiosk",
"priority": 72
},
"highlight": {},
"highlights": [],
"text_match": 100,
"text_match_info": {
"best_field_score": "0",
"best_field_weight": 12,
"fields_matched": 4,
"score": "100",
"tokens_matched": 0
}
},
{
"document": {
"code": "0",
"id": "0",
"name": "coll3 Pizza",
"priority": 53
},
"highlight": {},
"highlights": [],
"text_match": 100,
"text_match_info": {
"best_field_score": "0",
"best_field_weight": 12,
"fields_matched": 4,
"score": "100",
"tokens_matched": 0
}
},
{
"document": {
"code": "4",
"id": "4",
"name": "Icecream",
"priority": 49
},
"highlight": {},
"highlights": [],
"text_match": 100,
"text_match_info": {
"best_field_score": "0",
"best_field_weight": 12,
"fields_matched": 4,
"score": "100",
"tokens_matched": 0
}
},
{
"document": {
"code": "2",
"id": "2",
"name": "Cake",
"priority": 23
},
"highlight": {},
"highlights": [],
"text_match": 100,
"text_match_info": {
"best_field_score": "0",
"best_field_weight": 12,
"fields_matched": 4,
"score": "100",
"tokens_matched": 0
}
},
{
"document": {
"code": "1",
"id": "1",
"name": "coll3 Pizzeria",
"priority": 20
},
"highlight": {},
"highlights": [],
"text_match": 100,
"text_match_info": {
"best_field_score": "0",
"best_field_weight": 12,
"fields_matched": 4,
"score": "100",
"tokens_matched": 0
}
}
],
"out_of": 5,
"page": 1,
"request_params": {
"collection_name": "collection3",
"per_page": 10,
"q": "*"
},
"search_cutoff": false,
"search_time_ms": 0
}
]
}Aadarsh
10/25/2023, 3:34 PM{field}_sequence_id in the response? How can it be used in the search?Harpreet Sangar
10/26/2023, 4:02 AM{field}_sequence_id field is used internally to create a reference.
The name_tag field in collection2 has a reference to collection1.code. So we store the doc ids of collection1 that match those values in name_tag_sequence_id.
"name_tag": ["0", "1"],
"name_tag_sequence_id": [0, 1],
It's not meant to be used directly for search.Harpreet Sangar
10/26/2023, 4:39 AM'include_fields': '$collection1(*) as collection1,$collection3(*) as collection3'Aadarsh
10/26/2023, 5:05 AMsearch_requests = {'searches': [{'collection': 'collection1', 'q': 'kiosk', 'sort_by': 'priority:desc,_text_match:desc', 'prioritize_token_position': 'true'}, {'collection': 'collection2', 'q': 'kiosk', 'sort_by': 'priority:desc,_text_match:desc', 'prioritize_token_position': 'true', 'include_fields': '$collection1(*) as collection1,$collection3(*) as collection3'}, {'collection': 'collection3', 'q': 'kiosk', 'sort_by': 'priority:desc,_text_match:desc', 'prioritize_token_position': 'true'}]}
{
"results": [
{
"facet_counts": [],
"found": 1,
"hits": [
{
"document": {
"code": "3",
"id": "3",
"name": "tags Kiosk",
"priority": 72
},
"highlight": {
"name": {
"matched_tokens": [
"Kiosk"
],
"snippet": "tags <mark>Kiosk</mark>"
}
},
"highlights": [
{
"field": "name",
"matched_tokens": [
"Kiosk"
],
"snippet": "tags <mark>Kiosk</mark>"
}
],
"text_match": 578730123365705900,
"text_match_info": {
"best_field_score": "1108091339005",
"best_field_weight": 15,
"fields_matched": 1,
"score": "578730123365705849",
"tokens_matched": 1
}
}
],
"out_of": 5,
"page": 1,
"request_params": {
"collection_name": "collection1",
"per_page": 10,
"q": "kiosk"
},
"search_cutoff": false,
"search_time_ms": 0
},
{
"facet_counts": [],
"found": 1,
"hits": [
{
"document": {
"code": "3",
"collection1.code": [
"0",
"1",
"3"
],
"collection1.name": [
"tags Pizza",
"tags Pizzeria",
"tags Kiosk"
],
"collection1.priority": [
53,
20,
72
],
"collection3.code": "0",
"collection3.name": "coll3 Pizza",
"collection3.priority": 53,
"id": "0",
"name": "Kiosk",
"name_tag": [
"0",
"1",
"3"
],
"name_tag_sequence_id": [
0,
1,
3
],
"priority": 72,
"reference_collection_id": "0",
"reference_collection_id_sequence_id": 0
},
"highlight": {
"name": {
"matched_tokens": [
"Kiosk"
],
"snippet": "<mark>Kiosk</mark>"
}
},
"highlights": [
{
"field": "name",
"matched_tokens": [
"Kiosk"
],
"snippet": "<mark>Kiosk</mark>"
}
],
"text_match": 578730123366232200,
"text_match_info": {
"best_field_score": "1108091339262",
"best_field_weight": 15,
"fields_matched": 1,
"score": "578730123366232185",
"tokens_matched": 1
}
}
],
"out_of": 1,
"page": 1,
"request_params": {
"collection_name": "collection2",
"per_page": 10,
"q": "kiosk"
},
"search_cutoff": false,
"search_time_ms": 0
},
{
"facet_counts": [],
"found": 1,
"hits": [
{
"document": {
"code": "3",
"id": "3",
"name": "Kiosk",
"priority": 72
},
"highlight": {
"name": {
"matched_tokens": [
"Kiosk"
],
"snippet": "<mark>Kiosk</mark>"
}
},
"highlights": [
{
"field": "name",
"matched_tokens": [
"Kiosk"
],
"snippet": "<mark>Kiosk</mark>"
}
],
"text_match": 578730123366232200,
"text_match_info": {
"best_field_score": "1108091339262",
"best_field_weight": 15,
"fields_matched": 1,
"score": "578730123366232185",
"tokens_matched": 1
}
}
],
"out_of": 5,
"page": 1,
"request_params": {
"collection_name": "collection3",
"per_page": 10,
"q": "kiosk"
},
"search_cutoff": false,
"search_time_ms": 0
}
]
}Harpreet Sangar
10/26/2023, 5:08 AMcollection2 and collection1.Aadarsh
10/26/2023, 5:09 AMHarpreet Sangar
10/26/2023, 5:09 AMcollection2Aadarsh
10/26/2023, 5:12 AM'include_fields': '$collection1(*) as collection1,$collection3(*) as collection3' wasn't working. It used to get stuck.Harpreet Sangar
10/26/2023, 5:13 AM'include_fields': '$collection1(*),$collection3(*)' earlier? The difference is we've now added an alias by using asAadarsh
10/26/2023, 5:14 AM