Kalpesh
Kalpesh

Reputation: 83

Solr 5 how to search in specific field

I am using Solr version 5 for searching data. I am using below query which searches for keyword in all fields.

http://localhost:8983/solr/document/select?q=keyword1+keyword2&wt=json

Can anyone suggest me query to search for keyword only in title field.

Thanks.

Upvotes: 1

Views: 6325

Answers (3)

Sonu
Sonu

Reputation: 732

The best way is to run the query from Admin concole. When we run it, it also provides the actuall SQL query executed. Just copy the query and use it.

About the question: search specific field value from the Solr. In the admin console look for 'Q' text box. write the yourfield=value OR yourfield:value. Hit the 'Execute Query' button. Top right side the SQL will be available.

Generated Query: ......select?indent=on&q=YOURFIELD:"VALUE"&wt=json

Upvotes: 0

Karsten R.
Karsten R.

Reputation: 1758

You can not search for a keyword in all fields without some extra work:

How can I search all field in SOLR that contain the keywords,.?

The "q"-Parameter contains the query string and for the standard parser this means that you must specify the field via colon like in

fieldname:searchterm

or the standard parser will use the default field. The default field is specified in the "df"-Parameter and if you did not change your solrconfig.xml you will search in the "text"-Field because you will find something like

<requestHandler name="/select" class="solr.SearchHandler">
  <lst name="defaults">
    <str name="df">text</str>
  </lst>
</requestHandler>

P.S. If you want to search in all fields you have either to copy all field-content to one field or you must use a specific query parser like dismax parser, where you can list all your fields in the "qf"-Parameter.

P.P.S. You can not search in all fields but you can highlight in all fields :-)

Upvotes: 1

Azat Nugusbayev
Azat Nugusbayev

Reputation: 1421

use

   http://localhost:8983/solr/document/select?q=title:*yourkeyword*&wt=json

or for exact match

   http://localhost:8983/solr/document/select?q=title:"yourkeyword"&wt=json

Upvotes: 5

Related Questions