The ClauseContext field expression is used with JOIN queries. JOIN queries return results from multiple tables. If you request the "title" field in the results, you get title values from every type of document that participated in the join. ClauseContext lets us ask for the title values from some document types, while ignoring the titles of other types of documents.
Suppose you were to issue this query, which is similar to examples in the Quick Start Tutorial. Note that the query assigns the city table an alias ("cityTable") :
JOIN(table:country, INNER(table:city, alias="cityTable"), on=country)
This query returns country documents, with city documents listed as "child" documents. Suppose we want to see the title fields of all the city documents, but not of the country documents?
The solution is to use ClauseContext to filter the matching values so that only the city titles are returned:
CLAUSECONTEXT(FIELDEXPRESSION,JOINCLAUSE) AS ALIAS
- FIELDEXPRESSION - The stored field to operate on.
- JOINCLAUSE - An alias given to one of the join clauses in the query (see example above).
- ALIAS - New field name for the resulting value(s).
CLAUSECONTEXT(title,"cityTable") AS "city.title"
QueryRequest request = new QueryRequest("*:*)"); request.addField(new ClauseContext(new StoredField("title"),"cityTable").as("city.title")); // ... (Perform Search)