栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 前沿技术 > 大数据 > 大数据系统

Elasticsearch写sql进行index,mapping,suggest,analysis,query, aggs聚合等操作

Elasticsearch写sql进行index,mapping,suggest,analysis,query, aggs聚合等操作

#-------------------------1.创建、删除、查看mapping------------------------
#查看映射
GET /myindex/_mapping

#删除索引即可删除mapping
DELETE /myindex

#创建映射
PUT /myindex

    "mappings" : {
      "properties" : {
        "name" : {
          "type" : "text",
          "fields": {
            "keyword":{
              "type": "keyword",
              "ignore_above": 256
            },
            "suggest":{
              "type":"completion"
            }
          },
          "analyzer": "ik_max_word"
        },
        "fileType" : {
          "type" : "text"
        },
        "isAnalysis" : {
          "type" : "long"
        },
        "dataSource" : {
          "type" : "text" 
        },
        "station" : {
          "type" : "text",
          "fields" : {
            "keyword" : {
              "type" : "keyword",
              "ignore_above" : 256
            }
          }
        }
      }
    } 
}


#-------------------------2.创建、删除索引 index------------------------
#删除索引
DELETE /myindex

#创建索引
PUT /myindex

PUT myindex/_doc/1
{
  "body": "here"
}

#-------------------------3. 分词器------------------------
#获取分词器
GET myindex/_analyze
{
  "text": "太阳黑子分析工具"
}

#看分词效果 
GET _analyze
{
  "analyzer": "ik_max_word",   
  "text": "太阳黑子分析工具"
}

GET _analyze
{
  "analyzer": "ik_smart",
  "text": "太阳黑子分析工具"
}

GET _analyze
{
  "analyzer": "standard",
  "text": "太阳黑子分析工具"
}

#-------------------------4. suggest------------------------
GET myindex/_search
{
  "suggest": {
    "my_suggest": {
      "text": "分",
      "term": {
        "field":"name",
        "suggest_mode":"missing"
      }
    }
  }
}
 

GET myindex/_search
{
  "suggest": {
    "my_suggest": {
      "text": "太阳黑子",
      "completion":{
        "field":"name.suggest",
        "skip_duplicates": true  #去重
      }
    }
  }
}

GET _search
{
  "query": {
    "match_all": {}
  }
}

GET myindex/_search
{
  "query": {
    "match_all": {}
  }
}

GET myindex/_search
{
  "query":{
    "wildcard":{
      "name.keyword": {
        "value": "太阳黑子分析工具"
      }
    }
  }
}

GET myindex/_search
{
  "query":{
    "wildcard":{
      "name": {
        "value": "分析"
      }
    }
  }
}

GET myindex/_search
{
  "query": {
    "fuzzy":{
      "name":{
        "value":"太阳",
        "fuzziness": 0.5,  
        "prefix_length":0,
        "max_expansions":50,
        "transpositions":true,
        "boost":1.0
        
      }
      
    }
  }
}


GET myindex/_search
{
  "query":{
    "match_phrase":{
      "name":{
        "query": "太阳",
        "slop": 2
      }
    }
  }
}

GET myindex/_search
{
  "query":{
    "match_phrase":{
      "name":{
        "query":"太阳黑子分析工具",
        "slop":0,
        "zero_terms_query":"NONE",
        "boost":1.0
      }
      
    }
  }
}


 

#根据分析工具名称进行聚合
GET analysis_tool/_search
{
  "size": 0,
  "aggs": {
    "myNameAgg": {
      "terms": {
        "field": "name.keyword" 
      }
    }
  }
}

#同一个分析工具名称下,对站点进行聚合
GET analysis_tool/_search
{
  "size": 0,
  "aggs": {
    "myNameAgg": {
      "terms": {
        "field": "name.keyword"
      },
      "aggs": {
        "myNameStationAgg": {
          "terms": {
            "field": "station.keyword" 
          }
        }
      }
    }
  }
}
 

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/719033.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号