I am trying to index/search pdf file in java api from here:
After indexing, when I try to search it returns base64? How do I getback
the original text/source?
"_score" : 0.0047945753, "_source" :
{"name":"fn6742.pdf","file":"JVBERi0xLjQNJeLjz9MNCjE1OCAwIG9iaiA8PC9MaW5lYXJpemVkIDEvTCAzODExNDQvTyAxNjMvRSAyNDcxMS9OIDEzL1QgMzc3OTM
....
[Cyclone] [docs] deleting index
[2014-02-07 15:56:40,415][INFO ][cluster.metadata ] [Cyclone]
[docs] creating index, cause [api], shards [5]/[1], mappings []
[2014-02-07 15:56:40,537][INFO ][cluster.metadata ] [Cyclone]
[docs] create_mapping [pdf]
[2014-02-07 15:56:40,793][INFO ][cluster.metadata ] [Cyclone]
[docs] update_mapping [pdf] (dynamic)
[2014-02-07 16:07:11,040][INFO ][cluster.metadata ] [Cyclone]
[docs] deleting index
[2014-02-07 16:08:10,611][INFO ][cluster.metadata ] [Cyclone]
[docs] creating index, cause [api], shards [5]/[1], mappings []
[2014-02-07 16:08:10,732][INFO ][cluster.metadata ] [Cyclone]
[docs] create_mapping [pdf]
[2014-02-07 16:08:10,927][INFO ][cluster.metadata ] [Cyclone]
[docs] update_mapping [pdf] (dynamic)
Code:
private static void internalMain() throws Exception {
String fileContents = readContent( new File("fn6742.pdf") );
Client client = new TransportClient().addTransportAddress(new
InetSocketTransportAddress("localhost", 9300));
try {
DeleteIndexResponse deleteIndexResponse = new
DeleteIndexRequestBuilder( client.admin().indices(), INDEX_NAME ).execute().
actionGet();
if ( deleteIndexResponse.isAcknowledged() ) {
System.out.println( "Deleted index" );
}
} catch ( Exception e ) {
System.out.println("Index already deleted");
}
System.out.println("before index create call");
CreateIndexResponse createIndexResponse = new
CreateIndexRequestBuilder( client.admin().indices(), INDEX_NAME ).execute().
actionGet();
System.out.println("after index create call");
if ( createIndexResponse.isAcknowledged() ) {
System.out.println( "created index" );
}
PutMappingResponse putMappingResponse =
new PutMappingRequestBuilder( client.admin
().indices() ).setIndices(INDEX_NAME).setType( DOCUMENT_TYPE ).setSource(
jsonBuilder()
.startObject()
.field("doc"
)
.
startObject()
.field( "properties" )
.startObject()
.field( "file" )
.startObject()
.field( "term_vector",
"with_positions_offsets" )
.field( "store", "yes" )
.field( "type", "attachment")
//.field("index", "analyzed")
.endObject()
.endObject()
.
endObject()
.endObject()
).execute().actionGet();
if ( putMappingResponse.isAcknowledged() ) {
System.out.println( "successfully defined mapping"
);
}
IndexResponse indexResponse = client.prepareIndex(
INDEX_NAME , DOCUMENT_TYPE, "1")
.setSource(jsonBuilder()
.startObject()
.field("name","test/fn6742.pdf")
.field( "file", fileContents)
.field( "modified", new Date() )
.field( "updated_at", new Date() )
.endObject()
)
.execute()
.actionGet();
System.out.println( indexResponse );
client.admin().indices().refresh(refreshRequest()).actionGet();
//////////////////////// Search
///////////////////////////////////
SearchResponse searchResponse = client.prepareSearch(
INDEX_NAME )
.setSearchType(SearchType.QUERY_AND_FETCH)
.setQuery(fieldQuery("file", "200nA"))
//.setQuery(queryString("c"))
.setFrom(0)
.setSize(60)
.setExplain(true)
.execute()
.actionGet();
System.out.println( searchResponse );
client.close();
}
--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/087fb06d-46e4-44fb-9e54-018be4bacd9d%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.