c# - Equal query in Elasticsearch by Nest client -
c# - Equal query in Elasticsearch by Nest client -
public class user { public string email { get; set; } } client.index(new user { email ="test@test.te" });
query in linq c# illustration :
rep.where(user=>user.email=="test@test.te"); thats work correct.
i utilize same query in nest:
client.search<post>(q => q .query(qu => qu .term(te=>te.onfield("email").value("test@test.te")))); document result count zero!! :
client.search<post>(q => q .query(qu => qu .term(te=>te.onfield("email").value("test")))); document result count 1 !!why! how can create equal-quey in elasticsearch
it's because analyzers. document parsed terms while indexing, means elasticsearch stores array of strings ["test", "test", "te"] in row document. depending on anayzer configured (i guess it's standard one), may different terms decomposition. on other side, term request not analyzed; that's why first request returns nil - there's no such string "test@test.te" in index strings ["test", "test", "te"], there's "test" string, results sec one. in case should utilize query_string query, beware of fact such queries analyzed too. means, if index 2 documents, {"email":"test@test.te"} , {"email":"test@gmail.com"}, without flags query {"query":{"query_string":{"default_field":"email","query":"test@test.te"}}} homecoming both documents because both of them contain "test" string in index. avoid this, utilize {"default_field":"email","query":"test@test.te", "default_operator":"and"}}} - default default operator "or".
speaking of nest, utilize query like
client.search<post>(q => q .query(qu => qu .querystring(qs=>qs .onfield(x=>x.email).query("test@test.te").operator(operator.and) ) ) ); c# .net elasticsearch nest
Comments
Post a Comment