Page tree
Skip to end of metadata
Go to start of metadata

Quick Start

The following exercise builds on the Attivio Quick Start tutorial to introduce adding multi level facets using JAVA API. This is applicable from attivio installer 5.6.1


In order to complete the following exercise, you'll need to have the following software installed:

ApplicationRecommended VersionDownload LocationNotes
Maven3.5 or later 
EclipseOxygen or later sure to install the M2Eclipse plugin or use the Eclipse IDE for Java Developers installer which includes Maven integration.

Deploy the Attivio Factbook Project

Open the Attivio Quick Start Tutorial in a new tab in your browser, follow the instructions to deploy the Factbook project, run the connectors and return to this page when complete.

Build a search request

Create a Java class to create a search request and add multi level facets to it.  

          // Create query request. query to search should be assigned for queryString.
          QueryRequest request = new QueryRequest(queryString,QueryLanguages.SIMPLE);
    	  // create Facet requests on specific fields
          FacetRequest parentFacet = new FacetRequest("table");
          FacetRequest childFacet = new FacetRequest("country");
          FacetRequest grandChildFacet = new FacetRequest("language");
    	  //Facets needs to be added in an order. GrandChild facet to child, child to parent, parent to request.
    	  //Capture search response
          QueryResponse response =;

    Schema facet as a child facet

    SchemaFacetRequest childFacet = new SchemaFacetRequest("fields");

    Range facet as a Child Facet

    RangeFacetRequest childFacet = new RangeFacetRequest("size");
    childFacet.add("<150", 0, 150);

    Filter based Facet as a Child Facet

    FilterBasedFacetRequest parentFacet = new FilterBasedFacetRequest("table");
    parentFacet.add("table", new QueryString("table:city",QueryLanguages.SIMPLE));

    we can set these parameters at any level of facet

    parentFacet.setSortOrder(SortBy.COUNT, Sort.ASC);

    Drill down the response

    Access the facet buckets and their children from response object using below code

        System.out.println("Total documents matched: " + response.getDocuments().getNumberFound());
        FacetResponse facet = response.getFacet("table");  //capturing parent facet
        //access buckets using a loop
        for (FacetBucket bucket : facet) 
            System.out.println("Parent: " + bucket.getDisplayValue() + " " + bucket.getCount());
            FacetBuckets childBuckets = bucket.getChildren();
            Iterator iterator = childBuckets.iterator();
             FacetBucket childBucket = (FacetBucket);
             System.out.println("  child: " + childBucket.getDisplayValue() + " " + childBucket.getCount());
             // System.out.println("Facet filter of parent:"+facet.getFacetFilter(bucket));
             // System.out.println("facet filter of child "+facet.getFacetFilter(bucket,childBucket));   //following this order is very important.
             FacetBuckets grandChildBuckets = childBucket.getChildren();
             Iterator iterator1 = grandChildBuckets.iterator();
              FacetBucket grandChildBucket = (FacetBucket);
              System.out.println("    grandChild: " + grandChildBucket.getDisplayValue() + " " + grandChildBucket.getCount());


    • No labels