zoukankan      html  css  js  c++  java
  • 谷粒商城ES进阶和映射(十七)

    110、全文检索-ElasticSearch-进阶-两种查询方式-121 全文检索-ElasticSearch-映射-修改映射&数据迁移

    讲的也比较简单,就简单记录一下

    GET /bank/_search
    {
      "query": {
        "match_all": {}
      },
      "sort": [
        {
          "account_number": "asc"
        }
      ]
    }
    
    
    GET /bank/_search?q=*&sort=account_number:asc
    
    GET /bank/_search
    {
      "query": {
        "match": {
          "account_number": "20"
        }
      }
    }
    
    GET /bank/_search
    {
      "query": {
        "match": {
          "address": "Kings"
        }
      }
    }
    
    GET /bank/_search
    {
      "query": {
        "match": {
          "address": "mill lane"
        }
      }
    }
    
    ##会断检索条件进行分词匹配
    
    GET /bank/_search
    {
      "query": {
        "match_phrase": {
          "address": "132 Gunnison"
        }
      }
    }
    #注意,这个keyword是完全匹配
    GET /bank/_search
    {
      "query": {
        "match": {
          "address.keyword": " 132 Gunnison"
        }
      }
    }
    
    GET /bank/_search
    {
      "query": {
        "multi_match": {
          "query": "mill",
          "fields": ["address","city"]
        }
      }
    }
    
    
    GET /bank/_search?pretty
    {
      "query": {
        "bool": {
          "must": [
            {
              "match": {
                "gender": "F"
              }
            },
            {
              "match": {
                "age": "40"
              }
            }
          ],
          "must_not": [
            {
              "match": {
                "state": "ID"
              }
            }
          ],
          "should": [
            {
              "match": {
                "employer": "Suremax"
              }
            }
          ]
        }
      }
    }
    
    #使用filter不会计算相关性得分
    GET /bank/_search
    {
      "query": {
        "bool": {
          "filter": {
            "range": {
              "age": {
                "gte": 10,
                "lte": 20
              }
            }
          }
        }
      }
    }
    
    
    GET /bank/_search
    {
      "query": {
        "term": {
            "age": "30"
        }
      }
    }
    
    GET /bank/_search
    {
      "query": {
        "match": {
          "address": "mill"
        }
      },
      "aggs": {
        "ageAgg": {
          "terms": {
            "field": "age",
            "size": 10
          }
        },
        "ageAvg":{
          "avg": {
            "field": "age"
          }
        }
      },
      "size": 0
    }
    
    
    ##按照年龄聚合,并且请求这些年龄段的这些人的平均薪资
    GET /bank/_search
    {
      "query": {
        "match_all": {}
      },"aggs": {
        "ageAgg": {
          "terms": {
            "field": "age",
            "size": 10
          },
          "aggs": {
            "ageAvg": {
              "avg": {
                "field": "balance"
              }
            }
          }
        }
      }
    }
    
    
    ##查出所有年龄分布,并且这些年龄段中M的平均薪资和F的平均薪资以及这个年龄段的总体平均薪资
    GET /bank/_search
    {
      "query": {
        "match_all": {}
      },
      "aggs": {
        "ageAgg": {
          "terms": {
            "field": "age",
            "size": 100
          },
          "aggs": {
            "genderAvg": {
              "terms": {
                "field": "gender.keyword",
                "size": 10
              },
              "aggs": {
                "balanceAvg": {
                  "avg": {
                    "field": "balance"
                  }
                }
              }
            },
            "ageBalance":{
              "avg": {
                "field": "balance"
              }
            }
          }
        }
      }
    }
    
    
    
    ##新增映射规则
    PUT /my-index
    {
      "mappings": {
        "properties": {
          "age":    { "type": "integer" },  
          "email":  { "type": "keyword"  }, 
          "name":   { "type": "text"  }     
        }
      }
    }
    
    ##修改映射
    PUT /my-index/_mapping
    {
      "properties": {
        "employee-id": {
          "type": "keyword",
          "index": false
        }
      }
    }
    
    #进行数据迁移
    GET /bank/_mapping
    
    GET /newbank/_mapping
    
    PUT /newbank
    {
      "mappings": {
        "properties": {
          "account_number": {
            "type": "long"
          },
          "address": {
            "type": "text"
          },
          "age": {
            "type": "integer"
          },
          "balance": {
            "type": "long"
          },
          "city": {
            "type": "keyword"
          },
          "email": {
            "type": "keyword"
          },
          "employer": {
            "type": "keyword"
          },
          "firstname": {
            "type": "text"
          },
          "gender": {
            "type": "keyword"
          },
          "lastname": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword",
                "ignore_above": 256
              }
            }
          },
          "state": {
            "type": "text"
          }
        }
      }
    }
    
    
    POST _reindex
    {
      "source": {
        "index": "bank",
        "type": "account"
      },
      "dest": {
        "index": "newbank"
      }
    }
    
    GET /newbank/_search
  • 相关阅读:
    QFramework 使用指南 2020(二):下载与版本介绍
    QFramework 使用指南 2020 (一): 概述
    Unity 游戏框架搭建 2018 (二) 单例的模板与最佳实践
    Unity 游戏框架搭建 2018 (一) 架构、框架与 QFramework 简介
    Unity 游戏框架搭建 2017 (二十三) 重构小工具 Platform
    Unity 游戏框架搭建 2017 (二十二) 简易引用计数器
    Unity 游戏框架搭建 2017 (二十一) 使用对象池时的一些细节
    你确定你会写 Dockerfile 吗?
    小白学 Python 爬虫(8):网页基础
    老司机大型车祸现场
  • 原文地址:https://www.cnblogs.com/dalianpai/p/13138798.html
Copyright © 2011-2022 走看看