How to do field mapping in azure search for complex json objects for example nested array

喜欢而已 提交于 2021-01-27 15:59:00

问题


I have following problem I have a field mapping update to an index .Payload is complex where I have:

{
    "type": "abc",
    "Party": [{
        "Type": "abc",
        "Id": "123",
        "Name": "manasa",
        "Phone": [{
            "Type": "Office",
            "Number": "12345"
        }]
    }]
}

And now I want to create a field for an index. The field name is phonenumber of type Collection(Edm.String) where mapping is

{
"sourceFieldName" : "/Party/Phone/Number",
"targetFieldName" : "phonenumber",
"mappingFunction" : { "name" : "jsonArrayToStringCollection" }
}

In http post body But still after indexing i get phone number result as null.That means the mapping went wrong.If you see the phone number in source json, it is inside a json array and it itself is an array and result needs to get stored inside a collection of a string.Is it possible how can I achieve this? If this is not possible I atleast want field mapping till phone array ie., /Party/Phone/

If i index complete party array as a text, I get an error while running the index saying:

"Field 'partydetails' contains a term that is too large to process. The max length for UTF-8 encoded terms is 32766 bytes. The most likely cause of this error is that filtering, sorting, and/or faceting are enabled on this field, which causes the entire field value to be indexed as a single term. Please avoid the use of these options for large fields."

Can someone please help!


回答1:


If party would have been a Json object than an array and phone would have been only a string array for example

{
    "type": "abc",
    "Party": {
        "Type": "abc",
        "Id": "123",
        "Name": "manasa",
        "Phone": [{
            "12345",
            "23463"
        }]
    }
}

Then I could have mapped

{
    "sourceFieldName" : "Party/Phonenumber",
    "targetFieldName" : "phonenumbers",
    "mappingFunction" : { "name" : "jsonArrayToStringCollection" }
}

It map as collection of type odata EDM.string.

So to put this in better and straight forward way,

  1. Either transform your json to something flatter (the example that I gave above) or
  2. Use the proper index incase if you know before inhand as @Luis Cabrera said,

        “sourceFieldName”: “/Party/0/Phone/0/Type
    

It is a limitation from azure search side.




回答2:


Note that Party and Phone are arrays, so the field mapping you mention won't work.

You will need to index into the specific element. For example:

{
    "sourceFieldName": "/Party/0/Phone/0/Type",
    "targetFieldName": "firstPhoneNumberTypeOfFirstParty"
}

You may want to give that a shot.

Thanks!

Luis Cabrera | Program Manager | Azure Search



来源:https://stackoverflow.com/questions/48151575/how-to-do-field-mapping-in-azure-search-for-complex-json-objects-for-example-nes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!