首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >用fscrawler实现ElasticSearch文件映射并在C#中通过嵌套搜索文档

用fscrawler实现ElasticSearch文件映射并在C#中通过嵌套搜索文档
EN

Stack Overflow用户
提问于 2017-04-18 17:26:53
回答 1查看 911关注 0票数 0

我使用fscrawler 2.3-快照将文件夹"/tmp/es“中的文档编入索引。它将它们映射为:

代码语言:javascript
复制
{
  "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获得文件名.

代码:

代码语言:javascript
复制
 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

由于文件名嵌套在文件下,我现在无法检索滞留在这里几天的it...please帮助。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-04-19 21:21:17

发现错误:

我的文件课是:

代码语言:javascript
复制
Class documents
{
      Public string filename { get; set; }

      Public string content { get; set; }

      Public string url { get; set; }
}

由于文件名和url都是file.filenamefile.url,我们需要另一个带有文件名和url的类文件。

代码语言:javascript
复制
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访问它们。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43478625

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档