# Elasticsearch **Repository Path**: yangf_abc_admin/Elasticsearch ## Basic Information - **Project Name**: Elasticsearch - **Description**: No description available - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: dev - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2017-12-04 - **Last Updated**: 2020-12-19 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # Elasticsearch 教程 1. asdf ``` // 0. 初始化索引配置:分析器+索引工具版本 Analyzer an = new StandardAnalyzer(Version.LUCENE_4_9); IndexWriterConfig iwc = new IndexWriterConfig(Version.LUCENE_4_9, an); // 1. 指定索引位置 Directory dir = FSDirectory.open(new File("D:/Index")); // 2. 创建索引工具 IndexWriter iw = new IndexWriter(dir, iwc); // 3. 添加索引 Document doc = new Document();// 一条数据的格式,相当于数据库中一条数据 String str = "this is test elasticsearch code"; doc.add(new Field("fname", str, TextField.TYPE_NOT_STORED));// 相当于字段。 iw.addDocument(doc); // 4. 关闭连接,添加索引过程是加锁的,如果不关闭,将会导致其他程序无法写入,只有执行了close才会解锁。标识就是write.lock文件。 iw.close(); dir.close(); ```