【发布时间】:2016-02-12 22:56:07
【问题描述】:
我正在尝试对弹性中的数据执行 4 次操作。完全匹配(等于),包含,小于,大于。 elastic 有两个选项,即查询和过滤器,从我目前所学的内容来看,它们的作用相同,但查询评估的分数与数据条件-值关系最匹配。
我想做的是简单的过滤或查询(我很困惑,他们网站上提到的方式)
- 精确匹配,例如
name=Arjun或age=29或email=abc@asd.com - 包含类似名称包含
Ar或电子邮件包含gmail.com - 大于喜欢
age>29 - 不如
age<20
到目前为止,我一直在使用这种格式(坦率地说,我没有时间进行研究和实施)
{{ \"query\" : {{ \"filtered\" : {{ \"filter\" : {{ \"bool\" : {{ {{\"match\" : {\"" name "\" : \"" Arjun "\"} }} }} }} }} }} }}
包含以上格式
{{ \"query\" : {{ \"filtered\" : {{ \"filter\" : {{ \"bool\" : {{ {\"range\": {\"" age "\": {\"" + gt/lt+ "\": \"" 29 "\"} } } }} }} }} }} }}
大于或小于的格式
我使用 bool 表达式按此 URL 按过滤器进行组合 https://www.elastic.co/guide/en/elasticsearch/guide/current/_most_important_queries_and_filters.html
根据上面的链接,我们可以使用 bool 来组合查询,并按照示例中的指定
{
"bool": {
"must": { "match": { "title": "how to make millions" }},
"must_not": { "match": { "tag": "spam" }},
"should": [
{ "match": { "tag": "starred" }},
{ "range": { "date": { "gte": "2014-01-01" }}}
]
}
}
我可以在没有过滤器和内部过滤器的情况下编写相同的内容吗?
现在我想在我的(凌乱的)代码中实现 equals,我觉得它的代码也不太好。
请帮帮我
【问题讨论】:
-
我添加了 c# 作为标签,因为我使用 C# 创建查询并使用 webrequest 发送它
标签: elasticsearch