zoukankan      html  css  js  c++  java
  • elasticSearch 查询 term

    term

    term是代表完全匹配,即不进行分词器分析,文档中必须包含整个搜索的词汇

    {
        "term" : {
            "price" : 20
        }
    }
    
    # SELECT document FROM   products WHERE  price = 20
    

    通常当查找一个精确值的时候,我们不希望对查询进行评分计算。只希望对文档进行包括或排除的计算,所以我们会使用 constant_score 查询以非评分模式来执行 term 查询并以一作为统一评分。

    curl -X GET "localhost:9200/my_store/products/_search?pretty" -H 'Content-Type: application/json' -d'
    {
        "query" : {
            "constant_score" : {  # 我们用 constant_score 将 term 查询转化成为过滤器
                "filter" : {
                    "term" : { 
                        "price" : 20
                    }
                }
            }
        }
    }
    '
    

      

    terms

    curl -X GET "localhost:9200/my_store/products/_search?pretty" -H 'Content-Type: application/json' -d'
    {
        "query" : {
            "constant_score" : {
                "filter" : {
                    "terms" : { 
                        "price" : [20, 30]    # 这个 terms 查询被置于 constant_score 查询中
                    }
                }
            }
        }
    }
    '
    

      

    包含,而不是相等

    一定要了解 term 和 terms 是 包含(contains) 操作,而非 等值(equals)。

  • 相关阅读:
    前端性能优化
    CSS实现文字在容器中对齐方式
    spring里面的context:component-scan
    Builder模式
    idea无法新建maven项目
    Java-位运算
    pg数据库数据表异常挂起
    Java-多线程与单例
    Java-数据结构之二叉树练习
    Java-JNA使用心得
  • 原文地址:https://www.cnblogs.com/Mint-diary/p/14436392.html
Copyright © 2011-2022 走看看