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

Elasticsearch写sql进行index,mapping,suggest,analysis,query, aggs聚合等 *** 作,第1张

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" 
          }
        }
      }
    }
  }
}
 

欢迎分享,转载请注明来源:内存溢出

原文地址: http://www.outofmemory.cn/zaji/5715350.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-17
下一篇 2022-12-18

发表评论

登录后才能评论

评论列表(0条)

保存