Run queries from Hive on data indexed to Solr

Once a Hive external table is configured, any syntactically correct Hive query will be able to query the generated Solr index.

  • To query fields from a table:
    hive> SELECT [***FIELD NAME***], [***FIELD NAME***], [***FIELD NAME***] FROM [***TABLE NAME***];
    For example, to select three fields named "claim_id_s", "line_id_s", and "service_dt_i" from the "solr" table, run the following query:
    hive> SELECT claim_id_s, line_id_s, service_dt_i FROM solr;
  • To filter for rows:
    You can either use the standard WHERE conditions. In this case, Hive reads all the documents from Solr and executes the filter after that. This can be very inefficient.
    hive> SELECT * FROM [***TABLE***] WHERE [***FIELD NAME***]=’somestring’;
    If you have added the special solr_query column during table creation, it can be used to filter results by specifying query parameters for Solr.
    hive> SELECT * FROM [***TABLE***] WHERE solr_query='[***SOLR QUERY***]'
    You can specify multiple query parameters using the & delimiter.
    For example:
    hive> SELECT * FROM solr WHERE solr_query='fq=service_dt_s:1*'
    
    hive> SELECT * FROM solr WHERE solr_query='q=(1d)&df=service_dt_s'
    
    hive> SELECT * FROM solr WHERE solr_query="fq={!geofilt sfield=gps_p}&pt=46.9,16.9&d=11111"