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" }
                    }
                }
            }
        }
    }
  • 相关阅读:
    mysql索引及优化
    mysql5.5 uuid做主键与int做主键的性能实测
    php生成UUID
    Android 图片的裁剪与相机调用
    Android GPS 临近触发
    Android中GPS类及方法简介
    永久删除 tadb.exe
    linux服务器调整参数支持高并发
    隐藏nginx 版本号信息
    nginx 重写 rewrite 基础及实例
  • 原文地址:https://www.cnblogs.com/notchangeworld/p/11493642.html
Copyright © 2011-2022 走看看