Elasticsearch로 JSON 파일 가져 오기 / 인덱싱
저는 Elasticsearch를 처음 사용하며 지금까지 데이터를 수동으로 입력했습니다. 예를 들어 다음과 같은 작업을 수행했습니다.
$ curl -XPUT 'http://localhost:9200/twitter/tweet/1' -d '{
"user" : "kimchy",
"post_date" : "2009-11-15T14:12:12",
"message" : "trying out Elastic Search"
}'
이제 .json 파일이 있으며이 파일을 Elasticsearch로 인덱싱하고 싶습니다. 나도 이와 같은 것을 시도했지만 성공하지 못했습니다.
curl -XPOST 'http://jfblouvmlxecs01:9200/test/test/1' -d lane.json
.json 파일을 어떻게 가져 옵니까? 매핑이 올바른지 확인하기 위해 먼저 수행해야하는 단계가 있습니까?
curl과 함께 파일을 사용하려는 경우 올바른 명령은 다음과 같습니다.
curl -XPOST 'http://jfblouvmlxecs01:9200/test/_doc/1' -d @lane.json
Elasticsearch는 스키마가 없으므로 반드시 매핑이 필요하지 않습니다. json을있는 그대로 보내고 기본 매핑을 사용하면 모든 필드가 표준 분석기를 사용하여 인덱싱되고 분석됩니다 .
명령 줄을 통해 Elasticsearch와 상호 작용하려면 curl보다 약간 더 편리한 elasticshell 을 살펴 보는 것이 좋습니다.
2019-07-10 : 사용자 지정 매핑 유형 은 더 이상 사용되지 않으며 사용해서는 안됩니다. 위의 URL에있는 유형을 업데이트하여 "test"라는 이름을 가진 유형이 혼란 스러웠 기 때문에 색인과 유형을 쉽게 확인할 수 있도록했습니다.
현재 문서에 따라 http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/docs-bulk.html :
curl에 텍스트 파일 입력을 제공하는 경우 일반 -d 대신 --data-binary 플래그를 사용해야합니다. 후자는 개행을 보존하지 않습니다.
예:
$ curl -s -XPOST localhost:9200/_bulk --data-binary @requests
우리는 이런 유형의 도구를 만들었습니다 https://github.com/taskrabbit/elasticsearch-dump
나는 elasticsearch_loader의 저자입니다
.이 정확한 문제에 대해 ESL을 작성했습니다.
pip로 다운로드 할 수 있습니다.
pip install elasticsearch-loader
그런 다음 다음을 실행하여 json 파일을 elasticsearch에로드 할 수 있습니다.
elasticsearch_loader --index incidents --type incident json file1.json file2.json
KenH의 답변에 추가
$ curl -s -XPOST localhost:9200/_bulk --data-binary @requests
당신은 대체 할 수 @requests
와 함께@complete_path_to_json_file
참고 : @
파일 경로 앞에 중요합니다.
json 파일과 동일한 디렉토리에 있는지 확인한 다음 간단히 실행했습니다.
curl -s -H "Content-Type: application/json" -XPOST localhost:9200/product/default/_bulk?pretty --data-binary @product.json
따라서 당신도 같은 디렉토리에 있는지 확인하고 이런 식으로 실행하십시오. 참고 : 명령의 product / default /는 내 환경에 특정한 것입니다. 이를 생략하거나 자신과 관련된 것으로 바꿀 수 있습니다.
https://www.getpostman.com/docs/environments 에서 우편 배달부를 받으십시오. / test / test / 1 / _bulk? pretty 명령을 사용하여 파일 위치를 지정하십시오.
아무도 언급하지 않은 한 가지 : JSON 파일에는 "순수한"JSON 파일의 모든 줄에 대해 다음 줄이 속한 색인을 지정하는 한 줄이 있어야합니다.
IE
{"index":{"_index":"shakespeare","_type":"act","_id":0}}
{"line_id":1,"play_name":"Henry IV","speech_number":"","line_number":"","speaker":"","text_entry":"ACT I"}
그것 없이는 아무것도 작동하지 않으며 이유를 알 수 없습니다.
당신은 사용하고 있습니다
$ curl -s -XPOST localhost:9200/_bulk --data-binary @requests
'requests'가 json 파일이면이를 다음과 같이 변경해야합니다.
$ curl -s -XPOST localhost:9200/_bulk --data-binary @requests.json
이 전에 json 파일이 색인화되지 않은 경우 json 파일 내부의 각 행 앞에 색인 행을 삽입해야합니다. JQ로이 작업을 수행 할 수 있습니다. 아래 링크를 참조하십시오 : http://kevinmarsh.com/2014/10/23/using-jq-to-import-json-into-elasticsearch.html
Go to elasticsearch tutorials (example the shakespeare tutorial) and download the json file sample used and have a look at it. In front of each json object (each individual line) there is an index line. This is what you are looking for after using the jq command. This format is mandatory to use the bulk API, plain json files wont work.
if you are using VirtualBox and UBUNTU in it or you are simply using UBUNTU then it can be useful
wget https://github.com/andrewvc/ee-datasets/archive/master.zip
sudo apt-get install unzip (only if unzip module is not installed)
unzip master.zip
cd ee-datasets
java -jar elastic-loader.jar http://localhost:9200 datasets/movie_db.eloader
I wrote some code to expose the Elasticsearch API via a Filesystem API.
It is good idea for clear export/import of data for example.
I created prototype elasticdriver. It is based on FUSE
참고URL : https://stackoverflow.com/questions/15936616/import-index-a-json-file-into-elasticsearch
'IT TIP' 카테고리의 다른 글
D3.js :“Uncaught SyntaxError : Unexpected token ILLEGAL”? (0) | 2020.10.18 |
---|---|
객체 배열 선언 (0) | 2020.10.18 |
문서 추적에 버전 제어 (예 : Subversion)를 적용 할 수 있습니까? (0) | 2020.10.18 |
열 머리글 클릭시 WPF ListView / GridView 정렬을 만드는 가장 좋은 방법은 무엇입니까? (0) | 2020.10.18 |
Enter., Backspace 및 탐색 키가 Visual Studio 2010 w / Powertools / Resharper에서 응답하지 않습니다. (0) | 2020.10.18 |