Showing results for 
Search instead for 
Did you mean: 

Context Service Search

Cisco Employee
Cisco Employee

I will be starting a project for a customer that will make use of a number of Context Service features, including the "Search" capability. I've been experimenting with the current version (2.0.2) of Context Service's Search. I'd like to share my experiences and questions. I'd also like to get a summary of how the Search capability is currently working within Context Service 2.0.2.

I use custom fields and field sets in my Context Service objects. All of the fields are defined as follows:

  • publiclyAccessible: false
  • searchable: true
  • dataType: string
  • classification: ENCRYPTED

The special search keys seem to work very well and are quite predictable. However, searching based on the contents of fields seems strange.

For example, if I search for all Customer objects that contain the value "Ace" in the Field "MAR_NEW_001_USERNAME", then I successfully retrieve my single Customer object.

However, if I search for all Customer objects that contain the value "MAR" in the Field "MAR_NEW_001_USERNAME", then I get back a large number of records, none of which contain the value "MAR" in the "MAR_NEW_001_USERNAME" field. All of the records that I get back contain the value "MAR" in some other field. Any idea how I can control this better?

3 Replies 3


Hi Joseph,

   Can you share the query your using to perform the search?



The issue can be seen in the number of objects returned in the following code. Passing the two arguments "MAR_NEW_001_USERNAME" and "Ace" into the code will return a single Customer object (as expected). Passing the two arguments "MAR_NEW_001_USERNAME" and "MAR" into the code will return many Customers, Pods, and Requests (not as expected). The latter set of arguments should not return any objects.

    public static void main (final String [] args)


        if ((args.length < 2) || (0 != (args.length % 2)))

            SearchContextServiceStrange.usage ();

        boolean errored = false;



            CSConnection csConnection = null;



                csConnection = (CSConnection) DatabaseConnection.instance ().getConnection (CSConnection.CONNECTION_TYPE);

                final Connection connection = csConnection.getConnection ();

                final SearchParameters params = new SearchParameters ();

                for (int index = 0; index < args.length; index += 2)


                    final String fieldName = args[index];

                    final String value = args[index + 1];

                    System.out.println ("Value: " + value);

                    params.add (fieldName, value);


                final List < Customer > list1 = connection.getContextServiceClient ().search (Customer.class, params,;

                System.out.println ("Found " + list1.size () + " Customer(s)");

                for (final Customer bean : list1)

                    System.out.println (bean.getId ());

                final List < Request > list2 = connection.getContextServiceClient ().search (Request.class, params,;

                System.out.println ("Found " + list2.size () + " Requests(s)");

                for (final Request bean : list2)

                    System.out.println (bean.getId ());

                final List < Pod > list3 = connection.getContextServiceClient ().search (Pod.class, params,;

                System.out.println ("Found " + list3.size () + " Pod(s)");

                for (final Pod bean : list3)

                    System.out.println (bean.getId ());


            catch (Exception | Error e)


                errored = true;

                System.err.println ("Could not search Context Service -- Marked connection as bad: " + e);

                throw new PoolLogicException (e.getMessage () + ": " + e.getCause ());




                if (null != csConnection)

                    DatabaseConnection.instance ().returnConnection (csConnection, true); // Force a close() on the connection

                DatabaseConnection.instance ().shutdown ();



        catch (SQLException | PoolLogicException e)


            errored = true;

            System.err.println ("Problem searching: " + e);


        System.exit (errored ? -1 : 0);


Thanks to Tom Weissinger, this issue has been SOLVED. The core issue was that I was using the 2.0.2 version of the sdk extensions JAR file where I should have been using the 2.0.3 version of the sdk extensions JAR file.

Please make sure that you are using the latest and greatest versions of the Context Service JAR files.

Getting Started

Find answers to your questions by entering keywords or phrases in the Search bar above. New here? Use these resources to familiarize yourself with the community:

Recognize Your Peers