Updated on 2024-11-29 GMT+08:00

Including Collection Names in Query Results

Scenario

The default query result of Solr does not include a collection name. When querying multiple collections, users cannot distinguish the specific collection to which the data belongs because query results mix with each other. In this case, collection names need to be included in the query results.

Prerequisites

The Solr service has been installed.

Procedure

  1. For Solr Admin UI,

    In Raw Query Parameters, enter echoCollection=true&collection=collection_1,collection_2. collection_1 and collection_2 are the names of the collections to be searched for. The returned result contains the _collection_ field. The following is an example:

  2. For Java APIs,

    The example code is as follows:

    SolrQuery solrQuery = new SolrQuery()
    .setStart(start).setRows(rows)
    .setFields(returnFileds)
    .setQuery(mainQuery)
    .setFilterQueries(filterQuery);
    solrQuery.set("collection", collection);
    solrQuery.setParam("echoCollection",true);
    • If distrib=false is enabled when querying, the collection name is not included in the query result.
    • When only one collection is searched, the returned result cannot contain the collection name.