首页 > 编程知识 正文

opendistroforelasticsearch-kibana的中文应用

时间:2023-11-19 01:48:11 阅读:291877 作者:GHLL

本文将介绍opendistroforelasticsearch-kibana在中文应用中的使用方法和注意事项。

一、安装及配置

1、安装opendistroforelasticsearch-kibana

tar -xzvf opendistroforelasticsearch-kibana-version.tar.gz
cd opendistroforelasticsearch-kibana-version
./bin/kibana

2、配置opendistroforelasticsearch-kibana的中文环境

i18n.locale: "zh-CN"
console.format: "pretty"
timezone: Asia/Shanghai

二、中文插件的使用

1、安装elasticsearch-analysis-ik插件

cd elasticsearch-version
bin/elasticsearch-plugin install https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v7.10.2/elasticsearch-analysis-ik-7.10.2.zip

2、在Kibana中设置分词器

PUT _settings
{
  "index": {
    "analysis": {
      "analyzer": {
        "ik_max_word": {
          "tokenizer": "ik_max_word"
        },
        "ik_smart": {
          "tokenizer": "ik_smart"
        }
      }
    }
  }
}

三、中文搜索优化

1、使用中文分词器

使用elasticsearch-analysis-ik插件提供的中文分词器,可以更加准确地将中文进行分词,提高搜索的准确度。

2、扩展字符过滤器

对于一些特殊字符,可以通过扩展字符过滤器来对它们进行处理,提高搜索的效率。

PUT _settings
{
  "analysis": {
    "char_filter": {
      "my_mapping": {
        "type": "mapping",
        "mappings": [
          "+ =>plusplus",
          "- =>minusminus"
        ]
      }
    },
    "tokenizer": {
      "my_tokenizer": {
        "type": "whitespace"
      }
    },
    "analyzer": {
      "my_analyzer": {
        "char_filter": [
          "html_strip",
          "my_mapping"
        ],
        "tokenizer": "my_tokenizer",
        "filter": [
          "stop",
          "lowercase",
          "asciifolding"
        ]
      }
    }
  }
}

四、实现中文分组聚合

1、使用terms aggregation

terms aggregation可以将搜索结果按照指定的字段进行分组,并且可以对每个分组进行统计计算。

POST /data/_search
{
  "size": 0,
  "aggs": {
    "group_by_color": {
      "terms": {
        "field": "color.keyword",
        "size": 10,
        "order": {
          "avg_price": "desc"
        }
      },
      "aggs": {
        "avg_price": {
          "avg": {
            "field": "price"
          }
        }
      }
    }
  }
}

五、中文数据可视化

1、使用词云图

通过ECharts提供的词云图组件,可以对搜索结果中的高频词进行可视化展示。

var options = {
  series: [{
    type: 'wordCloud',
    sizeRange: [14, 80],
    rotationRange: [-90, 90],
    rotationStep: 45,
    shape: 'circle',
    width: '100%',
    height: '100%',
    top: '0%',
    left: '0%',
    right: '0%',
    bottom: '0%',
    data: [
      {
        name: 'Elasticsearch',
        value: 10000,
        textStyle: {
          normal: {
            color: 'black'
          },
          emphasis: {
            shadowBlur: 10,
            shadowColor: '#333'
          }
        }
      },
      {
        name: 'Kibana',
        value: 6181,
        textStyle: {
          normal: {
            color: 'black'
          },
          emphasis: {
            shadowBlur: 10,
            shadowColor: '#333'
          }
        }
      },
      {
        name: '中文',
        value: 4386,
        textStyle: {
          normal: {
            color: 'black'
          },
          emphasis: {
            shadowBlur: 10,
            shadowColor: '#333'
          }
        }
      }
    ]
  }]
};

var myChart = echarts.init(document.getElementById('myChart'));
myChart.setOption(options);

六、总结

本文介绍了在opendistroforelasticsearch-kibana中进行中文应用时的安装、配置、搜索优化、分组聚合和数据可视化等方面。对于需要处理中文数据的用户,可以根据本文提供的方法进行操作,提高搜索的效率和准确度。

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。