Reputation: 17388
I am trying to search for documents with an empty field. These attempts do not work:
var searchResult1 = client.Search<Doc>(s => s
.From(0)
.Size(10)
.Query(q => q
.Match(m => m
.Field(f => f.Attachment.Content)
.Query("")
)
)
);
var searchResult2 = client.Search<Doc>(x => x
.Query(query => query
.Term(term => term
.Field(new Field("Attachment.Content"))
.Value("")
)
)
);
Please note that Attachment is of type Nest.Attachment.
Upvotes: 0
Views: 254
Reputation: 186
Just to add up to @fubo's asnwer. Make sure you index the field as Keyword
THEN do a query search on term otherwise you will end up with no documents returned. (just as @cs0815, the author of the question, replied to the linked answer)
private void EnsureIndexExitstance()
{
var indexExists = _elasticClient.Indices.Exists(indexName);
if (!indexExists.Exists)
{
_elasticClient.Indices.Create(
indexName,
c => c.Map<Document>(mm =>
mm.Properties(p =>
p.Keyword(k =>
k.Name("fieldName")))));
}
}
Upvotes: 0
Reputation: 45947
did you already try Verbatim()
var searchResult2 = client.Search<Doc>(x => x
.Query(query => query
.Term(t => t.Verbatim()
.Field(f => f.x)
.Value("")
)
)
);
Upvotes: 2