c# - 'And' 'Or' Query in ElasticSearch -
c# - 'And' 'Or' Query in ElasticSearch -
public class user { public string email { get; set; } public int age { get; set; } public bool active { get; set; } } client.index(new user { email ="test@test.te" });
query in linq c# illustration :
rep.where(user=>user.email=="test@test.te" && (user.age>18 || user.active== true));
how create query elasticsearch (i mean same query in elasticsearch)?
you can utilize combination of :
range
filter age
field (reference) term
filter email
, active
fields (reference) a bool
filter should
clauses (equivalent or) combine age
, active
filters (reference) another bool
filter combine previous 1 email
filter in must
clause (equivalent and) a filtered
query able utilize filters defined above. it may useful know differences between query , filters.
you should end :
{ "query": { "filtered": { "filter": { "bool": { "must": [ { "term": { "email": "test@test.te" } }, { "bool": { "should": [ { "range": { "age": { "gt": 18 } } }, { "term": { "active": "true" } } ] } } ] } } } } }
note:
for query work, email field must not_analyzed
term filter looks exact same value.
c# .net linq elasticsearch
Comments
Post a Comment