【问题标题】:how to index a file with elasticsearch 5.5.1如何使用 elasticsearch 5.5.1 索引文件
【发布时间】:2018-01-09 22:11:17
【问题描述】:

我是 Elasticsearch 的新手。我已经成功安装了带有 Kibana、X-pack 和摄取附件的 Elasticsearch。我同时运行 Elasticsearch 和 Kibana。目前,我在 Windows 2012 服务器上使用默认选项进行安装,使其保持简单。我在另一个驱动器w\mydocs 上有一个目录,目前它只有 3 个纯文本文件,但我想添加其他文件类型,如 pdf 和 doc 文件类型。所以现在我想将这些文件放入 Elasticsearches 索引中。我尝试使用以下链接作为指南 Attaching pdf docs in Elasticsearch,但我无法让它工作。

这是我设置索引和管道的方式:

PUT _ingest/pipeline/docs 
{
  "description": "documents",
  "processors" : [
    {
      "attachment" : {
        "field": "data",
        "indexed_chars" : -1
      }
    }]
}
PUT myindex
{
  "mappings" : {
    "documents" : {
      "properties" : {
        "attachment.data" : {
          "type": "text",
          "analyzer": "standard"
        }
      }
    }
  }
}

然后要获取第一个文档,我使用以下命令: PUT localhost:9200/documents/1?pipeline=docs -d @/w/mydocs/README.TXT

我收到的错误是:

{
  "error": {
    "root_cause": [
      {
        "type": "parse_exception",
        "reason": "request body is required"
      }
    ],
    "type": "parse_exception",
    "reason": "request body is required"
  },
  "status": 400
}

【问题讨论】:

    标签: elasticsearch kibana


    【解决方案1】:

    您仍然必须将有效的 JSON 发送到 Elasticsearch,即使在索引二进制数据时也是如此。这意味着,您必须将文档编码为 base64,然后将其放入这样的 JSON 文档中

    {
      "data" : "base64encodedcontentofyourfile"
    }
    

    【讨论】:

    • 所以现在如果我输入以下内容:PUT localhost:9200/documents/1?pipeline=docs { "data": "base64_encode('w:\\myDocs\\README.TXT')" } 我收到非法 base64 字符 5f 参数异常
    • 您需要在客户端将文件内容转换为base64,然后将该字符串作为数据字段发送。只指定路径是行不通的。
    【解决方案2】:

    有人建议我不要使用摄取附件,而是使用 FsCrawler。我设法让 Fscrawler 工作,而无需将任何内容转换为 base64。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-10-24
      • 2017-06-29
      • 2015-02-03
      • 2017-06-25
      • 1970-01-01
      相关资源
      最近更新 更多