#community-help

Handling Nested Data and Indexing in Typescript

TLDR Ed asked about handling nested data in Typescript. Kishore Nallan recommended flattening the dictionary for searching, but clarified that fields only used for display don't need to be flattened.

Powered by Struct AI
15
21mo
Solved
Join the chat
Feb 02, 2022 (21 months ago)
Ed
Photo of md5-120c789e9edae8b90bf59cf0e2612b66
Ed
09:19 AM
Hi, does typescript support nested data?
[
{
    "data": {
        "idFS": "xx",
        "jobNumber": "myjobNumber",
        "applicationUrl": "",
        "idClient": "11111",
        "title": "Sales Development Training Pro",
        "language": "EN",
        "businessUnit": "my business unit",
        "company": "my company",
        "city": "Pittsburgh",
        "state": "Pennsylvania",
        "country": "United States",
        "employmentType": "Full-time",
        "contract": "Permanent",
        "entryLevel": "Experienced professionals",
        "jobField": "Sales",
        "category": "Construction/mining and trades",
        "recruiter": [
            "1st recruiter",
            "2nd recruiter"
        ],
        "applicationEnd": null,
        "postingDate": "2022-01-14T00:00:00+01:00",
        "postingDate_timestamp": 1642114800
    },
    "content": {
        "employmentType": "Full-time",
        "contract": "Permanent",
        "entryLevel": "Experienced professionals",
        "jobField": "Sales",
        "category": "Construction/mining and trades",
        "applicationEnd": null,
        "businessHL": "The company",
        "business": "",
        "taskHL": "What we expect",
        "task": "something",
        "profileHL": "Who we are looking for",
        "profile": "<p>Our Sales Development Training program offers competitive compensation and full benefits</p>",
        "offerHL": "<p>Your Benefits With Us</p>",
        "offer": "",
        "contactHL": "Contact",
        "contact": "<p>my contact</p>",
        "diversityHL": "Additional information",
        "diversity": "<p>some text.</p>",
        "headerImage": "/images/header/header_EN.jpg"
    },
    "_geoloc": {
        "lat": 40.5381372,
        "lng": -80.0506545
    }
}
]
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
09:21 AM
👋 Ed, Typesense does not support searching on of nested fields: you have to "flatten" the dict into top-level fields before indexing.
09:21
Kishore Nallan
09:21 AM
Ed
Photo of md5-120c789e9edae8b90bf59cf0e2612b66
Ed
09:23 AM
can i set the content data to index:false, I don't need to search there, usually that's just for displaying the job
09:23
Ed
09:23 AM
the data in data is used for filtering/searching
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
09:23 AM
Yeah, that's totally fine. You don't even need to specify the fields in the schema.
Ed
Photo of md5-120c789e9edae8b90bf59cf0e2612b66
Ed
09:24 AM
but i have to flatten it right?
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
09:24 AM
If you don't specify a field in the schema, that field is just stored and returned verbatim.
09:24
Kishore Nallan
09:24 AM
No need to flatten fields that are just part of the document for display. Need to flatten only if you want to search on them.
Ed
Photo of md5-120c789e9edae8b90bf59cf0e2612b66
Ed
09:24 AM
awesome
09:25
Ed
09:25 AM
I use the content just to display the job on the job page, the data is what I can search/filter
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
09:25 AM
Then data subfields have to be flattened out, like data.title, data.businessUnit etc. The content key can just exist as it is in nested format.
Ed
Photo of md5-120c789e9edae8b90bf59cf0e2612b66
Ed
09:28 AM
[
    {
        "idFS": "xx",
        "jobNumber": "myjobNumber",
        "applicationUrl": "",
        "idClient": "11111",
        "title": "Sales Development Training Pro",
        "language": "EN",
        "businessUnit": "my business unit",
        "company": "my company",
        "city": "Pittsburgh",
        "state": "Pennsylvania",
        "country": "United States",
        "employmentType": "Full-time",
        "contract": "Permanent",
        "entryLevel": "Experienced professionals",
        "jobField": "Sales",
        "category": "Construction/mining and trades",
        "recruiter": [
            "1st recruiter",
            "2nd recruiter"
        ],
        "applicationEnd": null,
        "postingDate": "2022-01-14T00:00:00+01:00",
        "postingDate_timestamp": 1642114800
    },
    "content": {
        "employmentType": "Full-time",
        "contract": "Permanent",
        "entryLevel": "Experienced professionals",
        "jobField": "Sales",
        "category": "Construction/mining and trades",
        "applicationEnd": null,
        "businessHL": "The company",
        "business": "",
        "taskHL": "What we expect",
        "task": "something",
        "profileHL": "Who we are looking for",
        "profile": "<p>Our Sales Development Training program offers competitive compensation and full benefits</p>",
        "offerHL": "<p>Your Benefits With Us</p>",
        "offer": "",
        "contactHL": "Contact",
        "contact": "<p>my contact</p>",
        "diversityHL": "Additional information",
        "diversity": "<p>some text.</p>",
        "headerImage": "/images/header/header_EN.jpg"
    },
    "_geoloc": {
        "lat": 40.5381372,
        "lng": -80.0506545
    }
}
]
09:29
Ed
09:29 AM
like so ?
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
09:37 AM
👍 yes