zoukankan      html  css  js  c++  java
  • elasticsearch新改变

     

    第一种:

    {
        "query" : {
            "filtered" : {
                "filter" : {
                    "range" : {
                        "age" : { "gt" : 30 } 
                    }
                },
                "query" : {
                    "match" : {
                        "last_name" : "smith" 
                    }
                }
            }
        }
    }

    在使用filtered的时候报错:

    {
      "error": {
        "root_cause": [
          {
            "type": "parsing_exception",
            "reason": "no [query] registered for [filtered]",
            "line": 3,
            "col": 22
          }
        ],
        "type": "parsing_exception",
        "reason": "no [query] registered for [filtered]",
        "line": 3,
        "col": 22
      },
      "status": 400
    }
    

      原因:过时,替换成:

    {
        "query" : {
            "bool" : {
                "filter" : {
                    "range" : {
                        "age" : { "gt" : 30 }
                    }
                },
                "must" : {
                    "match" : {
                        "last_name" : "smith"
                    }
                }
            }
        }
    }

    第二种:

    Fielddata is disabled on text fields by default. Set fielddata=true on [interests] in order to load fielddata in memory by uninverting the inverted index. Note that this can however use significant memory. Alternatively use a keyword field instead."

    具体的原因是聚合前需要大量的内存,聚合前,需要将相应的字段开启聚合:

    所以:

    PUT megacorp/_mapping/employee/
    {
      "properties": {
        "interests": { 
          "type":     "text",
          "fielddata": true
        }
      }
    }

    然后在进行查询:

    GET /megacorp/employee/_search
    {
        "aggs" : {
            "all_interests" : {
                "terms" : { "field" : "interests" },
                "aggs" : {
                    "avg_age" : {
                        "avg" : { "field" : "age" }
                    }
                }
            }
        }
    }
  • 相关阅读:
    随机性的控制
    856. 括号的分数
    376. 摆动序列(贪心算法)
    XGBoost 安装方法
    1405. 最长快乐字符串(贪心算法)
    1296. 划分数组为连续数字的集合(贪心算法)
    1353. 最多可以参加的会议数目(贪心算法)
    435. 无重叠区间(贪心算法)
    Array-数组-数据结构
    认识Redis和安装
  • 原文地址:https://www.cnblogs.com/notchangeworld/p/11493642.html
Copyright © 2011-2022 走看看