ElasticSearch : plain text file instead of JSON

2019-08-17 02:05发布

问题:

Interested in elasticsearch and working with txt files not json. Can elasticsearch support plain text file? If yes, Is there any java API, I can use ( I tested crud operations with postman on JSON document and it's working fine ) Thanks for the help.

回答1:

No, the elasticsearch document api supports only JSON.

But there is a workaround for this problem using ingestion pipelines running on ingestion nodes in your cluster https://www.elastic.co/guide/en/elasticsearch/reference/current/ingest.html . By defaut each elasticsearch server instance is a ingestion node.

Please have a look on this wery well described approach for CSV https://www.elastic.co/de/blog/indexing-csv-elasticsearch-ingest-node which is easily adaptable for flat files.

Another option is to use a second tool like Filebeat or Logstash for file ingestion. Have a look here: https://www.elastic.co/products/beats or here https://www.elastic.co/products/logstash

Having a Filebeat in place will solve many problems with minimal effort. Give it a chance ;)