Search code examples
azure-devopsazure-cognitive-searchazure-cognitive-services

How do I create an Azure Cognitive Search index for embedded document with $oid unique identifier type?


My current data structure is something like this,

"customer": {
        "_id": {
            "$oid": "623a4b1bdb6d0a1210fd0234"
        },
        "customerName": "Andrew Jr"
    },

I will need to create ACS (Azure Cognitive Search for the above data structure. So I was using something like this:

{
        "name": "customer",
        "type": "Edm.ComplexType", 
        "fields": 
        [
            {
            "name": "customerName",
            "type": "Edm.String",
            "searchable": true, 
            "filterable": true, 
            "sortable": true, 
            "facetable": true
            }
        ]
     },

But it will throw errors to me when I add the _id as a string data type, for example, below:

{
        "name": "customer",
        "type": "Edm.ComplexType", 
        "fields": 
        [
            {
                "name": "_id",
                "type": "Edm.String",
                "searchable": true, 
                "filterable": true, 
                "sortable": true, 
                "facetable": true
                },
            {
            "name": "customerName",
            "type": "Edm.String",
            "searchable": true, 
            "filterable": true, 
            "sortable": true, 
            "facetable": true
            }
        ]
     },

Any ideas how to add the following format to the search?

 "_id": {
        "$oid": "623a4b1bdb6d0a1210fd0234"
    },

Thanks,


Solution

  • Most likely you are getting the error is because of invalid name for the field (_id).

    Based on the naming rules defined here, a field name can only contain letters, numbers, underscores ("_") however the first character of the field name must be a letter.

    Since you are naming your field as _id, you will get an error.