• 1.常用命令


    简单创建索引和搜索

    分析器 (分词器 字符过滤器 分词过滤器)

    备份和删除

    mapping 对字符的描述

    自动纠错和补全

    1.创建索引

    http://192.168.65.131:9200/smartom_index
    

    2.查看索引:

    http://192.168.65.131:9200/_cat/indices?v
    

    3.插入数据【这样也就是说创建了一个文档为users】

    http://192.168.65.131:9200/smartom_index/users/101
    {
        "name":"smartom",
        "age":19
    }
    

    4.精确搜索

    http://192.168.65.131:9200/smartom_index/_search?q=name:smartom
    

    5.全词搜索

    http://192.168.65.131:9200/smartom_index/_search
    

    全文索引

    6.全词搜索 term

    term是代表完全匹配,即不进行分词器分析,文档中必须包含整个搜索的词汇

    GET smartom_index/users/_search
    {
      "query":{
        "term":{
          "name":{
            "value":"smartom"
          }
        }
      }
    }
    

    7.全词搜索 match 全文搜索查询

    分词查询

    GET smartom_index/users/_search
    {
      "query": {
        "match": {
          "name": "我是smartom你是谁"
        }
      }
    }
    

    分析器analyze

    1.分词器
    2.字符过滤器
    3.分词过滤器

    ES给我吗内置了若干个分析器类型。其中常用的是标准分析器,我们肯定需要扩展,并使用一些第三方分析器。

    Anaylyzer通常由一个Tokener(怎么分词),以及若干个TokenFilter(过滤分词) Character Filter(过滤字符)组成。

    8.创建一个分析器

    POST _analyze
    {
      "analyzer":"standard",
      "text":"我是smartom你是谁"
    }
    

    standard

    simple


    9. 一个分词器【filter?】

    POST _analyze
    {
      "tokenizer":"lowercase",
      "text":"SMARTOM"
    }
    

    也可以 在tokenizer里面写 standard

    10.一个过滤器:

    POST _analyze
    {
      "tokenizer": "standard",
      "filter": ["lowercase"],
      "text": "我是smartom你是谁"
    }
    

    11.字符过滤器:[过滤html代码]

    POST _analyze
    {
      "tokenizer": "standard",
      "char_filter": ["html_strip"],
      "text": "woshi<br><b>asdf</b>是"
    }
    

    13.创建一个过滤器:settings analysis analyzer 【在索引里面用来进行搜索】

    PUT smartom
    {
      "settings": {
        "analysis": {
          "analyzer": {
            "smartom-analyer":{
              "type":"custom",      //代表是自定义的
              "tokenizer":"standard",
               "char_filter":["html_strip"],
               "filter":["lowercase"]
            }
          }
        }
      }
    }
    

    14.创建仓库:

    前提指定repo路径 elasticsearch.yml
    path.repo: ["/tmp/esbak"]

    PUT _snapshot/mybackup
    {
      "type": "fs",
      "settings": {
        "location": "/tmp/esbak"
      }
    }
    

    15.备份索引:

    bak1 是备份名称 smartom_index 备份的索引名称

    PUT _snapshot/mybackup/bak1?wait_for_completion=true
    {
      "indices": "smartom_index"
    }
    

    16.删除索引

    DELETE smartom_index
    

    17.关闭索引

    POST smartom_index/_close
    

    18.恢复索引

    POST _snapshot/mybackup/bak1/_restore?wait_for_completion=true
    {
      "indices": "smartom_index"
    }
    

    19.查看当前插件

    GET _cat/plugins
    

    20.查看mapping当前文档 查看文档字段类型?

    GET smartom_index/_mappings
    

    21.创建mapping mapping对数据类型的基本描述

    POST /smartom_index/fulltext/_mapping
    {
        "properties": {
            "content": {
                "type": "text",
                "analyzer": "ik_max_word",
                "search_analyzer": "ik_max_word"
            }
        }
    }
    

    title 用ik分词器进行索引

    PUT smartom_index
    {
        "mappings": {
          "news":{          //索引名称
            "properties": {
                "title": {
                  "type":"text",
                  "analyzer": "ik_max_word"
                }
            }
          }
        }
    }
    

    22.修改文档中的类型?

    PUT smartom_index/_mapping/users
    {
      "properties": {
        "news": { 
          "type":     "text",
          "fields": {
            "keyword": {
              "type": "keyword",
              "ignore_above": 256
            }
          }
        }
      }
    

    23.搜索建议

  • 相关阅读:
    (mysql)卸载5.0安装6.05出现“Error Nr. 2003 : Can't connect to MySQL server on 'localhost' (10061). ”的解决办法
    (Redundancy)关于服务器冗余的几个疑问,请知道的帮忙解答.
    (C#)XML文件操作3
    POJ 3635 Full Tank(最短路径变形 + 优先队列)
    POJ 2286 The Rotation Game(DFS + 迭代加深)
    POJ 1141 Brackets Sequence(区间DP + 打印路径)
    POJ 3460 Booksort(IDA* + 估价函数设计)
    POJ 2908 Quantum(BFS + 优先队列)
    NOI 1997 积木游戏(解题报告)
    NYOJ 110 决斗(区间DP + 黑书例题)
  • 原文地址:https://www.cnblogs.com/subtract/p/8505294.html
Copyright © 2020-2023  润新知