I have Solr 5.3.1 and need to do query for all field except some field (what I need search in some field not retrieve fields this way to retrieve [/?q=query&fl=field1,field2,field3] )
i try with some solution but not work
1.How to exclude fields in a SOLR query [this soluation not work]
2.[the below solution work but take more time]
query = field1:"+txtSearch+"OR field1:"+ txtSearch+" OR field1:"+txtSearch
3.I set indexed="false" in data-config.xml it only Ignore search in this field but when I search for all fields http://localhost:8983/solr/test?q=query the query search in all field regardless indexed="false" OR true
I look for all this links
Retrieving specific fields in a Solr query?
How to exclude fields in a SOLR query
https://www.drupal.org/node/1933996
Use copyField
Here is how you can use this:
- Make all the field stored="true" and indexed="false"
- Also create a new field say cffield with multiValued="true", stored="false" and indexed="true"
Example Schema :
<field name="field1" type="string" indexed="false" stored="true"/>
<field name="field2" type="string" indexed="false" stored="true"/>
<field name="field3" type="string" indexed="false" stored="true"/>
....
<field name="cffield" type="string" indexed="true" stored="false" multiValued="true"/>
- Now all the field from you want to search, set source value of use copyField tag to copy from source field to dest
Example Schema :
<copyField source="field1" dest="cffield"/>
<copyField source="field2" dest="cffield"/>
....
Now you can search using
query = cffield:txtSearch
This will give you result from all the field you use copyField's source and cffield as dest
indexed="false"
needs to be mentioned in the schema.xml.
Once you modify the schema.xml, you need to re-index the data.(you need to re-start the server as well)
Then solr will not search in the fields which are not indexed.
And if you want to search in specific field you can use the field name and the search value for the field.
like
`q=field1:"value1"`
q=field1:value1 OR field2:value2
q=field1:value1 AND field2:value2
q=value1&fq=field2:value2&fq=field3:value3