Error in matching the empty String

Hi All,

Here i am using searchQuery in the Full text search,If i want get the record with the type = “” and type = “private”

SearchQuery.match(“private”).field(“type”) – Working

SearchQuery.match("").field(“type”) – Not Working

i want to get the records rather that private type, can any once help in this to get the records.

Hi,
You could use a boolean must_not query to achieve this. Assuming that your index contains only documents of these two types (empty and private types) you may try a boolean query like below.

curl -XPOST -u uname:pwd  -H "Content-Type: application/json" http://127.0.0.1:9200/api/index/IndexName/query -d '{
"query": {"must_not": {"disjuncts": [{"field": "type", "match": "private"}]}}}' 

Cheers!
Sreekanth

i was tried with the above scenerio , i used like

const BooleanQuery = new SearchQuery.BooleanQuery();
BooleanQuery.mustNot(SearchQuery.match(“private”).field(“type”))

but i am getting some documents which having the type “Private”

Can you share your index definition to understand this better.