Selecting complex fields conditionally

Copper Contributor

If would be really helpful if we can select complex fields conditionally and only include those matched. We have a profile and each profile is on one or more networks.

value": [{

    "@search.score": 1.0,

    "FirstName": "John",

    "LastName": "Smith",

    "Networks": [

        {

            "NetworkID": 1,

            "NetworkName": "Network 1",

        },

        {

            "NetworkID": 2,

            "NetworkName": "Network 2",

        },

        {

            "NetworkID": 3,

            "NetworkName": "Network 3",

        },

    ]

},

{

    "@search.score": 1.0,

    "FirstName": "Erin",

    "LastName": "Earn",

    "Networks": [

        {

            "NetworkID": 2,

            "NetworkName": "Network 2",

        },

        {

            "NetworkID": 5,

            "NetworkName": "Network 5",

        },

    ]

},

Basically those profile is shared across netwoks that have been added as the part of the search document. 

search request = 

{

   "search":"",

   "filter":"Networks/any(network: network/NetworkID eq 5)",

   "select":"FirstName,LastName,Networks/any(network: network/NetworkID eq 5)", <= somethign like this?? I am not sure if we can conditionally select only theose collection fields that matches the criteria.

   "count":true,

   "queryType": "full"

}

search response =>

{

    "@search.score": 1.0,

    "FirstName": "Erin",

    "LastName": "Earn",

    "Networks": [

        {

            "NetworkID": 2,

            "NetworkName": "Network 2",

        },

        {

            "NetworkID": 5,

            "NetworkName": "Network 5",

        },

    ]

},

1 Reply


Hello @dipeshnepal ,

To conditionally select only those collection fields that match a certain criteria, you can use the "filter" parameter in the search request to filter the documents based on your criteria, and then use the "select" parameter to specify the fields to return.

In your example, you are filtering the documents based on the Network ID of 5. To return only the Networks collection that match this criteria, you can use the following "select" parameter:


"select": "First-name, Last Name, Networks/Network ID, Networks/Network Name"

This will return only the first name, last name, and Networks collection fields that match the filter criteria, which is Network ID of 5.

I hope this helps! Let me know if you have any further questions.

Kind Regards,

Luke Madden.
"Simplifying Tech, Empowering You."