I am using below query to get the elastic search results in php.
{
"query": {
"filtered": {
"query": {
"query_string": {
"query": "q= (\"Agriculture\" OR \"Agribusiness\" OR \"Agriculture\") et_tax= \"Agriculture\" -et_tax:\"Agriculture\""
}
}
}
},
"aggs": {
"lawfirmcount": {
"cardinality": {
"field": "pd_lawfirmID",
"precision_threshold": 1250
}
}
}
}
When is use the above code, it will fetch unmatched results. Is there anything wrong in that query.
It looks like you are querying on the same field,
et_tax, twice. In the first case, where the term "Agriculture" is present, and then again where "Agriculture" is not present (-et_tax:). I would expect this to return all documents, since the term "Agriculture" either exists or does not exist in the fieldet_tax, and the default operator forquery_stringisOR.Take a look at the documentation for
query_string. You can change thedefault_operatorto beANDinstead.Also, I suggest removing the double quotes from your search values, assuming they are not part of the term you are searching on.
Finally, I don't see a
qfield in your mapping. I don't think the "q=" in your query is working as you are expecting. You probably need to remove that and specify adefault_fieldto query against.Hope this helps...