簡體   English   中英

ElasticSearch 文件映射使用 fscrawler 並在 C# 中通過 NEST 搜索文檔

[英]ElasticSearch file mapping using fscrawler and searching doc by NEST in C#

我使用 fscrawler 2.3-SNAPSHOT 索引了文件夾“/tmp/es”中的文檔。 它將它們映射為:

{
  "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 ,將 url 顯示為file.url ,將 content 顯示為content

由於文件名嵌套在文件下,我無法檢索它......請幫助卡在這里幾天......

發現錯誤:

我的文檔類是:

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

      Public string content { get; set; }

      Public string url { get; set; }
}

由於 filename 和 url 與file.filenamefile.url ,我們需要另一個帶有 filename 和 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訪問它們。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM