ElasticSearch & attachment type (NEST C#)

后端 未结 4 2039
孤城傲影
孤城傲影 2020-12-09 21:07

I\'m trying to index a pdf document with elasticsearch/NEST.

The file is indexed but search results returns with 0 hits.

I need the search result to return o

4条回答
  •  被撕碎了的回忆
    2020-12-09 21:48

    // I am using FSRiver plugin - https://github.com/dadoonet/fsriver/

    void Main()
    {
        // search in document
        string query = "directly"; // test.pdf contains the string "directly"
        var es = new ElasticClient(new ConnectionSettings( new Uri("http://*.*.*.*:9200"))
            .SetDefaultIndex("mydocs")
            .MapDefaultTypeNames(s=>s.Add(typeof(Doc), "doc")));
            var result = es.Search(s => s
            .Fields(f => f.Title, f => f.Name)
            .From(0)
            .Size(10000)
                .Query(q => q.QueryString(qs => qs.Query(query)))
                .Highlight(h => h
                    .PreTags("")
                    .PostTags("")
                    .OnFields(
                      f => f
                        .OnField(e => e.File)
                        .PreTags("")
                        .PostTags("")
                    )
                )
            );
    }
    
    [ElasticType(Name = "doc",  SearchAnalyzer = "standard", IndexAnalyzer = "standard")]
    public class Doc
    {
        public int Id { get; set; }
    
         [ElasticProperty(Store = true)]
         public string Title { get; set; }
    
        [ElasticProperty(Type = FieldType.attachment, TermVector = TermVectorOption.with_positions_offsets)]
        public string File { get; set; }
        public string Name { get; set; }
    }
    

提交回复
热议问题