如何使用 elasticsearch 5.5.1 索引文件

how to index a file with elasticsearch 5.5.1

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

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

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 发送有效的 JSON,即使在索引二进制数据时也是如此。这意味着,您必须将文档编码为 base64,然后将其放入 JSON 文档中,如下所示

{
  "data" : "base64encodedcontentofyourfile"
}

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