#community-help

Issues with Typesense Search and JSON Formatting

TLDR Babin had issues with not getting all fields in a search. The problem was due to a JSON formatting extension in VS Code. Jason also clarified the requirement of query_by in multi-search POST method.

Powered by Struct AI

2

1

1

17
7mo
Solved
Join the chat
Mar 16, 2023 (7 months ago)
Babin
Photo of md5-aece7b06eda2a85a5bcfb5fd39332e2c
Babin
08:25 PM
Hi Jason
I am using below search

{
    "searches": [
        {
            "collection": "nic-items",
            "q": "-R - ",
            "page": 1,
            "per_page": 250,
            "include_fields": "id,sku,description,categoryName,brand,packSizeDescription"
        }
    ]
}

However I don't get all fields that are mentioned in include_fields
This is what we get
Image 1 for Hi <@4L6c7>
I am using below search
```<https://xxxxxxxxxxxxx.typesense.net/multi_search?query_by=sku,brand,description>
{
    "searches": [
        {
            "collection": "nic-items",
            "q": "-R - ",
            "page": 1,
            "per_page": 250,
            "include_fields": "id,sku,description,categoryName,brand,packSizeDescription"
        }
    ]
}```
However I don't get all fields that are mentioned in include_fields
This is what we get
Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
08:36 PM
Are all those fields present in all the documents?
Babin
Photo of md5-aece7b06eda2a85a5bcfb5fd39332e2c
Babin
08:38 PM
will that matter, one document could have brand, but not other one, we created some of the fields as optional in collection schema
Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
08:38 PM
I meant to say, does that particular example document you shared have those fields?

If it does, could you DM me your cluster ID? I can take a closer look
Babin
Photo of md5-aece7b06eda2a85a5bcfb5fd39332e2c
Babin
08:50 PM
if [[ $# -eq 3 && $1 == 'get-single-document' ]]
then
    curl "${TYPE_SENSE_HOSTURL}/collections/${2}/documents/${3}" \
                                             -X GET \
                                             -H "X-TYPESENSE-API-KEY: ${TYPE_SENSE_API_MASTER_KEY}"
                                             
fi

This one gives me more than one documents
08:50
Babin
08:50 PM
Am I missing anything
09:03
Babin
09:03 PM
This is the exported JSONL
Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
09:19 PM
Will take a look in about 15 mins
Babin
Photo of md5-aece7b06eda2a85a5bcfb5fd39332e2c
Babin
09:19 PM
Thanks
Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
09:50 PM
In the JSON response you shared, I do see other fields for that SKU
Image 1 for In the JSON response you shared, I do see other fields for that SKU
Babin
Photo of md5-aece7b06eda2a85a5bcfb5fd39332e2c
Babin
09:50 PM
Let me check
09:50
Babin
09:50 PM
I might have been missing something very basic
09:57
Babin
09:57 PM
Thanks Jason, you know what happened. I was using a JSON formatter in VS Code, I found on whatever file I do format, it kept bringing a file from cache, Then I started investigating other collection, which is a small test collection. And I found the root cause of that stupid extension

1

1

09:58
Babin
09:58 PM
Thank you very much

1

10:00
Babin
10:00 PM
Once quick question I have, if you don't mind.
In multi-search POST method, is it mandatory to send query_by

The GET search without query_by works .

${TYPE_SENSE_HOSTURL}/collections/${2}/documents/search?q=*&amp;page=1&amp;per_page=250&amp;exclude_fields=images,salesSheet
Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
10:12 PM
For q=* queries, query_by is not required. Otherwise it is required
Babin
Photo of md5-aece7b06eda2a85a5bcfb5fd39332e2c
Babin
10:12 PM
got it thanks

1