Sto cercando di indicizzare un documento PDF con elasticsearch/NEST.ElasticSearch e tipo di allegato (NEST C#)
Il file viene indicizzato ma i risultati della ricerca vengono restituiti con 0 risultati.
Ho bisogno risultato della ricerca per restituire solo l'ID del documento e il risultato clou
(senza il contenuto Base64)
Ecco il codice:
Io apprezzo qualsiasi aiuto qui,
Grazie,
class Program
{
static void Main(string[] args)
{
// create es client
string index = "myindex";
var settings = new ConnectionSettings("localhost", 9200)
.SetDefaultIndex(index);
var es = new ElasticClient(settings);
// delete index if any
es.DeleteIndex(index);
// index document
string path = "test.pdf";
var doc = new Document()
{
Id = 1,
Title = "test",
Content = Convert.ToBase64String(File.ReadAllBytes(path))
};
var parameters = new IndexParameters() { Refresh = true };
if (es.Index<Document>(doc, parameters).OK)
{
// search in document
string query = "semantic"; // test.pdf contains the string "semantic"
var result = es.Search<Document>(s => s
.Query(q =>
q.QueryString(qs => qs
.Query(query)
)
)
.Highlight(h => h
.PreTags("<b>")
.PostTags("</b>")
.OnFields(
f => f
.OnField(e => e.Content)
.PreTags("<em>")
.PostTags("</em>")
)
)
);
if (result.Hits.Total == 0)
{
}
}
}
}
[ElasticType(
Name = "document",
SearchAnalyzer = "standard",
IndexAnalyzer = "standard"
)]
public class Document
{
public int Id { get; set; }
[ElasticProperty(Store = true)]
public string Title { get; set; }
[ElasticProperty(Type = FieldType.attachment,
TermVector = TermVectorOption.with_positions_offsets)]
public string Content { get; set; }
}
Inoltre, ha verificato che i mapper-allegati plugin installato e caricato (utilizzando es.yml: plugin.mandatory: mapper -attachments). Ancora, nessun colpo per le parole contenute nel mio pdf. Ho cercato su Google le risposte a questo argomento (StackOverflow e altro) e ho trovato solo esempi di arricciature, nessun esempio di utilizzo con C#/NEST. (solo una nota: durante la ricerca di document.title ('test.pdf') riesco a recuperare il documento ma non ci sono risultati durante la ricerca 'test'. –
solo per farti sapere che ho intenzione di creare test di integrazione per questo domani e rispondere alla domanda. Non sono in grado di rispondere prima. –
eventuali aggiornamenti su questa domanda? – slimflem