# elastic **Repository Path**: nanaya1173/elastic ## Basic Information - **Project Name**: elastic - **Description**: 尝试结合django和elastic search使用,同时使用了ES的全文搜索特性 - **Primary Language**: Unknown - **License**: Apache-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2023-03-24 - **Last Updated**: 2026-06-22 ## Categories & Tags **Categories**: Uncategorized **Tags**: ElasticSearch, 全文搜索, 文档文件文本提取 ## README # elastic #### 介绍 项目基本说明:基于Elastic Search实现用非关系数据库NoSql实现的全文搜索: 1. 因nosql和sql形式上就不同,虽然有一些概念能辅助理解,但是大部份需要从基础开始熟悉),其概念上类似但使用上完全不同于sql的query language(查询语言):DSL查询(Query DSL) 2. 对一些第三方库的作用和试用做了一些调查了解,主要是关心版本匹配易用度,第三方库的可维护/扩展性 1)elasticsearch-dsl:基于官方库的二次封装,更符合面向对象和pythonic设计的用法 2)django-elasticsearch-dsl:集成框架 3)django_elasticsearch_dsl_drf:集成框架中rest用法 4)django-haystack:用于框架和第三方搜索引擎对接(可同时用于多种不同的搜索引擎对接,代码还不用改动,目前暂不考虑引用增加项目配置的复杂性) 5)IK Analyzer:ES引擎中用于分词的插件 注1: DSL是Elasticsearch提供的一种丰富且灵活的查询语言,该语言以json请求体的形式出现,通过restful请求与Elasticsearch进行交互。 注2: ES 和 postgreSQL 全文搜索做取舍 => ES性能强,postgreSQL全文搜索是使用方便以及数据集成关联性更高。目前决定先试用ES IK分词版本下载地址 https://github.com/medcl/elasticsearch-analysis-ik/releases/ You can manulally download the packaged plugins from here: https://release.infinilabs.com, 使用说明:下载相近的版本,解压后修改plugin-descriptor.properties文件里面的elasticsearch.version就可以 1. 首先打开C:\Program Files\elasticseach-8.11.1\plugins目录,新建一个名为ik的子目录, 并将elasticsearch-analysis-ik-8.11.1.zip包解压到该ik目录内也就是C:\Program Files\elasticseach-8.11.1\plugins\ik目录。 2. 首先将elascticsearch和kibana服务重启。 3. 然后地址栏输入http://localhost:5601,在Dev Tools中的Console界面的左侧输入命令,再点击绿色的执行按钮执行。 GET _analyze { "analyzer": "ik_max_word", "text": "上海自来水来自海上" } #### 软件架构 软件架构说明 #### 安装教程 1. 环境安装 Elastic Search(默认端口号9200) 2. 环境安装 Kibana(默认端口号5601) 3. (ES8版本默认包含在module之中)安装插件:Ingest Attachment Processor Plugin Ingest Attachment Processor Plugin是一个文本抽取插件,本质上是利用了Elasticsearch的ingest node功能,提供了关键的预处理器attachment。在安装目录下运行以下命令即可安装 ./bin/elasticsearch-plugin install ingest-attachment 4. 安装插件:IK分词器 You can manulally download or you can use the plugin cli to install the plugin like this: bin/elasticsearch-plugin install https://get.infini.cloud/elasticsearch/analysis-ik/8.4.1 Tips: replace your own version number related to your elasticsearch or opensearch. 5. 建立对应的pipeline(Ingest Attachment Processor Plugin)用于文件文档的文本提取 PUT /_ingest/pipeline/attachment { "description": "Extract attachment information", "processors": [ { "attachment": { "field": "content", "ignore_missing": true } }, { "remove": { "field": "content" } } ] } 6. 建立对应的数据接口 PUT /docwrite { "mappings": { "properties": { "id":{ "type": "keyword" }, "name":{ "type": "text", "analyzer": "ik_max_word" }, "type":{ "type": "keyword" }, "attachment": { "properties": { "content":{ "type": "text", "analyzer": "ik_smart" } } } } } } #### 使用说明 1. 在ElasticSearch和Kibana的bin目录里面的同名bat来启动对应的服务 2. ES 使用指南:https://www.elastic.co/guide/en/elasticsearch/reference/7.17/getting-started.html 3. 参考地址:https://www.cnblogs.com/strongchenyu/p/13777596.html 4. 如果内存占用过大,参考:https://www.elastic.co/guide/en/elasticsearch/reference/8.11/advanced-configuration.html 示例参考: 1)C:\Users\36045\Desktop\es\elasticsearch-8.11.1\config\jvm.options.d 中新建一个文件xmx.options 2)该文件内容为:-Xmx1024m 5. ES7:可以使用ES自带的java版本,更改文件 bin/elasticsearch-env.bat 里的字段 ES_JAVA_HOME 例如: set ES_JAVA_HOME=C:\Users\36045\Desktop\es\elasticsearch-7.17.9\jdk 6. ES8:需要关闭安全验证。首先找到cofig目录下elasticsearch.yml文件。更改替换该文件内的内容如下: xpack.security.enabled: false xpack.security.http.ssl: enabled: false