2017-04-18 50 views
0

我使用fscrawler 2.3-SNAPSHOT爲位於文件夾「/ tmp/es」中的文檔編制索引。它映射他們爲:使用fscrawler進行ElasticSearch文件映射並使用CEST中的NEST搜索文檔#

{ 
    "properties" : { 
    "attachment" : { 
     "type" : "binary", 
     "doc_values": false 
    }, 
    "attributes" : { 
     "properties" : { 
     "group" : { 
      "type" : "keyword" 
     }, 
     "owner" : { 
      "type" : "keyword" 
     } 
     } 
    }, 
    "content" : { 
     "type" : "text" 
    }, 
    "file" : { 
     "properties" : { 
     "content_type" : { 
      "type" : "keyword" 
     }, 
     "filename" : { 
      "type" : "keyword" 
     }, 
     "extension" : { 
      "type" : "keyword" 
     }, 
     "filesize" : { 
      "type" : "long" 
     }, 
     "indexed_chars" : { 
      "type" : "long" 
     }, 
     "indexing_date" : { 
      "type" : "date", 
      "format" : "dateOptionalTime" 
     }, 
     "last_modified" : { 
      "type" : "date", 
      "format" : "dateOptionalTime" 
     }, 
     "checksum": { 
      "type": "keyword" 
     }, 
     "url" : { 
      "type" : "keyword", 
      "index" : true 
     } 
     } 
    }, 
    "object" : { 
     "type" : "object" 
    }, 
    "meta" : { 
     "properties" : { 
     "author" : { 
      "type" : "text" 
     }, 
     "date" : { 
      "type" : "date", 
      "format" : "dateOptionalTime" 
     }, 
     "keywords" : { 
      "type" : "text" 
     }, 
     "title" : { 
      "type" : "text" 
     }, 
     "language" : { 
      "type" : "keyword" 
     } 
     } 
    }, 
    "path" : { 
     "properties" : { 
     "encoded" : { 
      "type" : "keyword" 
     }, 
     "real" : { 
      "type" : "keyword", 
      "fields": { 
      "tree": { 
       "type" : "text", 
       "analyzer": "fscrawler_path", 
       "fielddata": true 
      } 
      } 
     }, 
     "root" : { 
      "type" : "keyword" 
     }, 
     "virtual" : { 
      "type" : "keyword", 
      "fields": { 
      "tree": { 
       "type" : "text", 
       "analyzer": "fscrawler_path", 
       "fielddata": true 
      } 
      } 
     } 
     } 
    } 
    } 
} 

現在,我想在我的C#應用​​程序中使用NEST搜尋它們,我能夠hit.source.content得到內容但不能被hit.source.filename得到的文件名...

代碼:

var response = elasticClient.Search<documents>(s => s 
       .Index("tanks") 
       .Type("doc") 
       .Query(q => q.QueryString(qs => qs.Query(query)))); 

      if (rtxSearchResult.Text != " ") 
      { 
       rtxSearchResult.Text = " "; 

       foreach (var hit in response.Hits) 
       { 


        rtxSearchResult.Text = rtxSearchResult.Text + ("Name: " + hit.Source.fileName.ToString() 
        + Environment.NewLine 
        + "Content: " + hit.Source.content.ToString() 
        + Environment.NewLine 
        + "URL: " + hit.Source.url.ToString() 
        + Environment.NewLine 
        + Environment.NewLine); 
       } 
      } 

上述拋出NULLException但運行時,我的評論符合hit.Source.urlhit.Source.filename

Kibana顯示文件名字段爲file.filename,網址爲file.url,內容爲content

作爲文件名,文件下嵌套,我無法找回......請幫助困在這裏夫婦現在天..

+0

你的'文件'類型是什麼樣的?你能證明嗎? –

回答

0

發現錯誤:

我的文檔類是:

Class documents 
{ 
     Public string filename { get; set; } 

     Public string content { get; set; } 

     Public string url { get; set; } 
} 

由於文件名和網址分別爲file.filenamefile.url,我們需要另一個帶有文件名和url的類文件。

Class documents 
{ 
     Public File file { get; set; } 

     Public string content { get; set; } 

} 

Class File 
{ 
      Public string filename { get; set; } 

      Public string url { get; set; } 
} 

,因此,我能夠通過hit.Source.file.filenamehit.Source.file.url訪問它們。

相關問題