zoukankan      html  css  js  c++  java
  • elasticsearch7.x-指定分析器-分析器优先级

    指定分析器

    Elasticsearch提供了多种方式去指定内置或者自定义分析器

    • 通过文本字段、索引、查询

    • 在索引文档或者搜索文档时

    索引时分析器优先级

    Elasticsearch依次检查下面参数来决定使用哪个索引分析器

    1. mapping中对文本字段是否配置了分析器

    2. setting中是否配置了analysis.analyzer.default(索引全局默认分析器)

    3. 如果1,2都没有配置,standard 分析器将被使用

    为一个字段指定分析器

    PUT my-index-000001
    {
      "mappings": {
        "properties": {
          "title": {
            "type": "text",
            "analyzer": "whitespace"
          }
        }
      }
    }

    为一个索引指定默认分析器

    PUT my-index-000001
    {
      "settings": {
        "analysis": {
          "analyzer": {
            "default": {
              "type": "simple"
            }
          }
        }
      }
    }

    搜索时分析器优先级

    Elasticsearch依次检查下面参数来决定使用哪个搜索分析器

    1. 在query语句中是否指定了分析器

    2. 在mapping中是否配置了搜索分析器,参数是search_analyzer

    3. 在setting中是否配置了analysis.analyzer.default_search(搜索默认分析器)

    4. 在mapping中是否配置了分析器,参数是analyzer(索引分析器)

    查询语句中配置搜索分析器

    GET my-index-000001/_search
    {
      "query": {
        "match": {
          "message": {
            "query": "Quick foxes",
            "analyzer": "stop"
          }
        }
      }
    }

    为字段配置搜索分析器

    PUT my-index-000001
    {
      "mappings": {
        "properties": {
          "title": {
            "type": "text",
            "analyzer": "whitespace",
            "search_analyzer": "simple"
          }
        }
      }
    }

    为搜索配置默认搜索分析器

    PUT my-index-000001
    {
      "settings": {
        "analysis": {
          "analyzer": {
            "default": {
              "type": "simple"
            },
            "default_search": {
              "type": "whitespace"
            }
          }
        }
      }
    }
  • 相关阅读:
    查询语句
    索引的增删改成查
    pymysql模块
    mysql备份
    单表查询语法
    单表查询
    mysql增删改差
    Leetcode--1. Two Sum(easy)
    Leetcod--20. Valid Parentheses(极简洁的括号匹配)
    Leetcode-448. Find All Numbers Disappeared in an Array(solve without extra space easy)
  • 原文地址:https://www.cnblogs.com/zxbdboke/p/14562660.html
Copyright © 2011-2022 走看看