Hello,World
elasticsearch_mapper attachment插件

elasticsearch_mapper attachment插件

通过elasticsearch-mapper attachment插件实现文件建立索引

Elasticsearchpaopao 发表了文章 • 5 个评论 • 10600 次浏览 • 2016-01-06 10:28 • 来自相关话题

1.安装elasticsearch-mapper attachment bin/plugin install elasticsearch/elasticsearch-mapper-attachments/3.1.1  2.按照插件官方文档来测试 3.插件需要手动把文档内容转化为base64编码然后建立索引,代码如下 import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import org.apache.tika.Tika; import org.apache.tika.config.TikaConfig; import org.apache.tika.metadata.Metadata; import org.apache.tika.parser.AutoDetectParser; import org.apache.tika.parser.ParseContext; import org.apache.tika.parser.Parser; import org.apache.tika.parser.pdf.PDFParser; import org.apache.tika.sax.BodyContentHandler; import org.elasticsearch.action.index.IndexResponse; import org.elasticsearch.client.Client; import org.elasticsearch.client.transport.TransportClient; import org.elasticsearch.common.settings.ImmutableSettings; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.transport.InetSocketTransportAddress; import org.elasticsearch.common.xcontent.XContentBuilder; import org.xml.sax.ContentHandler; import com.spatial4j.core.io.ParseUtils; import static org.elasticsearch.common.xcontent.XContentFactory.*; public class sysfiles {     public static void main(String[] args) throws Exception{         sys(); }     private static void sys() throws IOException {         // TODO Auto-generated method stub         String idxName = "test";         String idxType = "attachments";         Settings settings =ImmutableSettings.settingsBuilder().put("cluster.name","az_bsms_elasticsearch").build();         Client client=new TransportClient(settings).addTransportAddress(new InetSocketTransportAddress("127.0.0.1", 9300));        String data64=org.elasticsearch.common.Base64.encodeFromFile(filepath);         XContentBuilder source = jsonBuilder().startObject()             .field("file", data64)                 .field("text", data64)                 .endObject();         String id = "file"+11;         IndexResponse idxResp = client.prepareIndex().setIndex(idxName).setType(idxType).setId(id)                 .setSource(source).setRefresh(true).execute().actionGet();         System.out.println(idxResp);         client.close();     } 4.按官方文档正常的搜索就可以了

通过elasticsearch-mapper attachment插件实现文件建立索引

Elasticsearchpaopao 发表了文章 • 5 个评论 • 10600 次浏览 • 2016-01-06 10:28 • 来自相关话题

1.安装elasticsearch-mapper attachment bin/plugin install elasticsearch/elasticsearch-mapper-attachments/3.1.1  2.按照插件官方文档来测试 3.插件需要手动把文档内容转化为base64编码然后建立索引,代码如下 import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import org.apache.tika.Tika; import org.apache.tika.config.TikaConfig; import org.apache.tika.metadata.Metadata; import org.apache.tika.parser.AutoDetectParser; import org.apache.tika.parser.ParseContext; import org.apache.tika.parser.Parser; import org.apache.tika.parser.pdf.PDFParser; import org.apache.tika.sax.BodyContentHandler; import org.elasticsearch.action.index.IndexResponse; import org.elasticsearch.client.Client; import org.elasticsearch.client.transport.TransportClient; import org.elasticsearch.common.settings.ImmutableSettings; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.transport.InetSocketTransportAddress; import org.elasticsearch.common.xcontent.XContentBuilder; import org.xml.sax.ContentHandler; import com.spatial4j.core.io.ParseUtils; import static org.elasticsearch.common.xcontent.XContentFactory.*; public class sysfiles {     public static void main(String[] args) throws Exception{         sys(); }     private static void sys() throws IOException {         // TODO Auto-generated method stub         String idxName = "test";         String idxType = "attachments";         Settings settings =ImmutableSettings.settingsBuilder().put("cluster.name","az_bsms_elasticsearch").build();         Client client=new TransportClient(settings).addTransportAddress(new InetSocketTransportAddress("127.0.0.1", 9300));        String data64=org.elasticsearch.common.Base64.encodeFromFile(filepath);         XContentBuilder source = jsonBuilder().startObject()             .field("file", data64)                 .field("text", data64)                 .endObject();         String id = "file"+11;         IndexResponse idxResp = client.prepareIndex().setIndex(idxName).setType(idxType).setId(id)                 .setSource(source).setRefresh(true).execute().actionGet();         System.out.println(idxResp);         client.close();     } 4.按官方文档正常的搜索就可以了