I created a new index with the following code :
private static void createIndex(Client xpClient) throws
JsonGenerationException, JsonMappingException, IOException {
CreateIndexRequest cri = new CreateIndexRequest("documentale");
HashMap<String,Object> indice = new HashMap<String,Object>();
HashMap<String,Object> documento = new HashMap<String,Object>();
HashMap<String,Object> mappings = new HashMap<String,Object>();
HashMap<String,Object> properties = new
HashMap<String,Object>();
HashMap<String,Object> contenuto = new HashMap<String,Object>();
contenuto.put("type","attachment");
contenuto.put("_content_type", "application/pdf");
properties.put("contenuto", contenuto);
documento.put("properties", properties);
mappings.put("documento",documento);
indice.put("mappings", mappings);
StringWriter sw = new StringWriter();
mapper.writeValue(sw, indice);
String json = sw.getBuffer().toString();
System.out.println(json);
cri.source(json);
xpClient.admin().indices().create(cri).actionGet();
}
Then I inserted a document using :
HashMap<String,Object> mappa = new HashMap<String,Object>();
mappa.put("user", "Tullio");
mappa.put("data", new Date());
mappa.put("message", "La vispa teresina avea tra");
long inizio = new Date().getTime();
FileInputStream fis = new
FileInputStream("C:\Tmp\mac_A17882.pdf");
byte[] contiene = IOUtils.toByteArray(fis);
String contenuto = new String(JsonUtils.encode(contiene));
mappa.put("contenuto", contenuto);
StringWriter sw = new StringWriter();
mapper.writeValue(sw, mappa);
String json = sw.getBuffer().toString();
System.out.println(json);
IndexResponse irb =
c.prepareIndex("documentale","documento","2").setSource(json).execute().actionGet();
and I tried to find it using :
mappa = new HashMap<String,Object>();
HashMap<String,Object> query = new HashMap<String,Object>();
HashMap<String,Object> term = new HashMap<String,Object>();
term.put("contenuto", "BARALDI");
query.put("term", term);
mappa.put("query", query);
sw = new StringWriter();
mapper.writeValue(sw, mappa);
json = sw.getBuffer().toString();
System.out.println(json);
SearchResponse response =
c.prepareSearch("documentale").setTypes("documento").setSource(json).execute().actionGet();
SearchHits sh = response.getHits();
But I got no results.
I'm sure the pdf document contains the "BARALDI" string.
What I mmissed ?
What's wrong ?
Tks
Tullio