elasticsearch - 搜索等于,包含,全文,小于,大于弹性

标签 elasticsearch

我试图对驻留在 flex 中的数据执行4个操作。完全匹配(等于),包含,小于,大于。 flex 中有两个选项,即查询和过滤器,从到目前为止我学到的内容中可以做到相同,但查询会评估与数据条件-值关系最匹配的分数。

我想要做的是简单的过滤或查询(我很困惑,在他们的网站中提到的方式)

  • 完全匹配,例如name=Arjunage=29email=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(boolean) 表达式根据此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,我感觉它的代码也不是很好。

    请帮我

    最佳答案

    使用如下查询:

    {
     "query": {
      "bool": {
         "must": [
            {
               "term": {
                  "name": "Arjun"
               }
            },
            {
               "query_string": {
                  "default_field": "name",
                  "query": "Ar*"
               }
            },
            {
               "range": {
                  "age": {
                     "from": 10,
                     "to": 20
                  }
               }
            }
           ]
          }
         }
       }
    

    关于elasticsearch - 搜索等于,包含,全文,小于,大于弹性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35363871/

    相关文章:

    Elasticsearch 奇怪的排序结果

    python - 如何在不更改类型的情况下从 SearchQuerySet 获取 n 个搜索对象?

    elasticsearch - 将现有集合嵌套在对象内

    elasticsearch - Elastic Search Function Score Query 添加 multi_match

    elasticsearch - Elasticsearch dis_max查询,返回完全匹配的查询

    elasticsearch - Elasticsearch,计算不包括的术语

    elasticsearch - 无法从 org.elasticsearch.common.bytes.BytesArray@0 派生 xcontent

    Elasticsearch 重建索引 : How do you direct updates to the new index while it is being built?

    elasticsearch - 在多节点集群中,elasticsearch.yml 将应用于哪个节点?

    java - ElasticSearch Java API :NoNodeAvailableException: No node available