Nikhil Agarwal
08/13/2023, 12:28 PMCustomerProductPrices
collection, would it fetch the product automatically or would that require a filter clause as well? Currently the examples seem to be mainly about fetching from Products
collection which doesn't have the reference field.Nikhil Agarwal
08/13/2023, 5:10 PMNikhil Agarwal
08/13/2023, 6:46 PM"filter_by":"$ItemCommon(itemNumber:!='')",
Harpreet Sangar
08/14/2023, 5:09 AMCustomerProductPrices
soon. It won't require any filter clause but you'll have to specify include_fields: $Products(*)
to get all the fields of related product or specific field names.Harpreet Sangar
08/14/2023, 5:34 AMOne more concern is if we can allow a product price to be added before the corresponding product (allow reference to not be enforced during data entry). I got an error when I tried to add the price before the product.
When a document containing a reference field is created, we lookup the referenced collection and store a reference in
foo_sequence_id
field. That's the reason for enforcing the presence of product.Harpreet Sangar
08/14/2023, 5:36 AMNikhil Agarwal
08/14/2023, 6:24 AM// Collection 1 - item_master
{
"name": "item_master",
"enable_nested_fields": true,
"fields": [
{
"name": "id",
"type": "string",
"index": true,
"optional": false,
"sort": true,
"infix": true,
"facet": true
},
{
"name": "attrId",
"type": "string",
"index": true,
"optional": true,
"infix": true,
"facet": true
},
{
"name": "itemNumber",
"type": "string",
"index": true,
"optional": true,
"sort": true,
"infix": false,
"reference": "items.itemNumber"
},
{
"name": "name",
"type": "string",
"index": true,
"optional": false
}
]
}
// 2nd collection "items"
{
"name": "items",
"enable_nested_fields": true,
"fields": [
{
"name": "itemNumber",
"type": "string",
"index": true,
"optional": true,
"sort": true,
"infix": false
},
{"name": "notes", "type": "string"},
{ "name": "guideType", "type": "int32", "index": true, "optional": false, "sort": false , "infix": false}
]
}
Nikhil Agarwal
08/14/2023, 6:24 AMNikhil Agarwal
08/14/2023, 6:26 AM{
"itemNumber": "123456",
"notes": "TEst Item 1",
"guideType": 1
}
And then to item_master
{
"_id": "abc",
"itemNumber": "123456",
"name": "Test Item 1"
}
@Harpreet Sangar On a side note, please also note this is an example of why I need item_master
to have an item even though items
collection doesn't have it (given how current join works which can change)Nikhil Agarwal
08/14/2023, 6:26 AMNikhil Agarwal
08/14/2023, 8:17 AMHarpreet Sangar
08/14/2023, 8:21 AMNikhil Agarwal
08/16/2023, 1:19 PMHarpreet Sangar
08/17/2023, 5:37 AMcurl -k "<http://localhost:8108/collections>" -X POST -H "Content-Type: application/json" -H "X-TYPESENSE-API-KEY: ${TYPESENSE_API_KEY}" -d '{
"name": "item_master",
"enable_nested_fields": true,
"fields": [
{
"name": "id",
"type": "string",
"index": true,
"optional": false,
"sort": true,
"infix": true,
"facet": true
},
{
"name": "attrId",
"type": "string",
"index": true,
"optional": true,
"infix": true,
"facet": true
},
{
"name": "itemNumber",
"type": "string",
"index": true,
"optional": true,
"sort": true,
"infix": false,
"reference": "items.itemNumber"
},
{
"name": "name",
"type": "string",
"index": true,
"optional": false
}
]
}'
curl -k "<http://localhost:8108/collections>" -X POST -H "Content-Type: application/json" -H "X-TYPESENSE-API-KEY: ${TYPESENSE_API_KEY}" -d '{
"name": "items",
"enable_nested_fields": true,
"fields": [
{
"name": "itemNumber",
"type": "string",
"index": true,
"optional": true,
"sort": true,
"infix": false
},
{"name": "notes", "type": "string"},
{ "name": "guideType", "type": "int32", "index": true, "optional": false, "sort": false , "infix": false}
]
}'
curl "<http://localhost:8108/collections/items/documents/import?action=create>"
-H "X-TYPESENSE-API-KEY: ${TYPESENSE_API_KEY}"
-H "Content-Type: text/plain"
-X POST
-d '{"itemNumber": "123456", "notes": "TEst Item 1", "guideType": 1}'
curl "<http://localhost:8108/collections/item_master/documents/import?action=create>"
-H "X-TYPESENSE-API-KEY: ${TYPESENSE_API_KEY}"
-H "Content-Type: text/plain"
-X POST
-d '{"_id": "abc", "itemNumber": "123456", "name": "Test Item 1"}'
curl -H "X-TYPESENSE-API-KEY: ${TYPESENSE_API_KEY}" "<http://localhost:8108/collections/items/documents/search?q=*>\
&filter_by=$item_master(itemNumber:!='')"
Harpreet Sangar
08/17/2023, 5:38 AM{
"facet_counts": [],
"found": 1,
"hits": [
{
"document": {
"guideType": 1,
"id": "0",
"itemNumber": "123456",
"notes": "TEst Item 1"
},
"highlight": {},
"highlights": []
}
],
"out_of": 1,
"page": 1,
"request_params": {
"collection_name": "items",
"per_page": 10,
"q": "*"
},
"search_cutoff": false,
"search_time_ms": 0
}
Nikhil Agarwal
08/17/2023, 3:06 PMHarpreet Sangar
08/17/2023, 3:56 PM