• 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" }
                    }
                }
            }
        }
    }
  • 相关阅读:
    tcp_wrapper过滤
    cobbler无人值守批量安装Linux系统
    PXE+kickstart无人值守安装CentOS 7
    kickstart文件详解
    SHELL脚本--shell数组基础
    SHELL脚本--管道和重定向基础
    第4章 DHCP服务
    第3章 NFS基本应用
    man sm-notify(sm-notify命令中文手册)
    man statd(rpc.statd中文手册)
  • 原文地址:https://www.cnblogs.com/notchangeworld/p/11493642.html
Copyright © 2020-2023  润新知