2017-10-17 1 views
0

나는 아래의 형식을 가지고 있으며 elasticsearch를 사용하여 대량으로 사전 처리하기를 원합니다.탄성 검색을 위해 JSON 형식을 일괄 변경하는 방법

{"title":"April","url":"https://simple.wikipedia.org/wiki/April", "abstract":"April is the 4th month of the year, and comes between March and May. It is one of four months to have 30 days.","sections":["The Month","April in poetry","Events in April","Fixed Events","Moveable Events","Selection of Historical Events","Trivia","References"]} 
{"title":"August","url":"https://simple.wikipedia.org/wiki/August", "abstract":"August (Aug.) is the 8th month of the year in the Gregorian calendar, coming between July and September.","sections":["The Month","August observances","Fixed observances and events","Moveable and Monthlong events","Selection of Historical Events","Trivia","References"]} 

인덱스를 추가하려고 할 때 각 줄 앞에 입력하십시오. 읽기 이전 게시물에

{"index":{"_index":"myindex","_type":"wiki","_id":"1"}} 

나는 아래와 같은 Kevin Marsh's post을 사용하고 있습니다 :

cat file.json jq -c '.[] | {"index": {"_index": "myindex", "_type": "wiki", "_id": .id}}, .' 

는 내가 그런거 오류 JQ를 얻을 앞에있는 오류를 파악하려고으로 파이프를 사용하고 있지 않다 : 그러한 파일이나 디렉토리가 없습니다. 그런 다음 jq --version and get jq-1.5-1-a5b5cbe을 사용했습니다.

도움을 주시면 감사하겠습니다.

+0

필요한 것을 모릅니다. –

+0

감사합니다. Hatim은 내 고양이 진술에 문제가 있거나 탄성 검색을 사용하여 대량 API를 준비 할 수있는 형식을 변경하는 더 좋은 해결책을 찾고자했습니다. – ESLearner

+0

제 생각에 json 파일이 있고 Bulk API를 사용하여 Elasticsearch에서 색인을 생성하려고합니다. 권리? –

답변

0

여기 있습니다. 이것은 나를 위해 일했다. 이것이 도움이되는지 알려주십시오.

cat data.json | jq -c '. | {"index": {"_index": "json", "_type": "json"}}, .' | curl -XPOST localhost:9200/_bulk --data-binary @- 

jq : a lightweight and flexible command-line JSON processor에 대해 자세히 알아보십시오.

+0

앞으로 계속 포맷 할 것입니다. 미안합니다. Hatim은 당신이 준 포맷으로 아래 명령을 사용했습니다 : – ESLearner

+0

cat data.json | jq -c '. | { "index": { "_index": "json", "_type": "json"}},. ' | curl -XPOST localhost : 9200/_bulk --data-binary @ - 다음 오류가 발생합니다. jq : error : 구문 오류, 예기치 않은 $ end (UNIX 쉘 인용 문제) , 줄 1 – ESLearner

+0

컬 부분을 잊어 버립니다. 이 "cat data.json | jq -c"를 시도해보십시오. | { "index": { "_index": "json", "_type": "json"}} "당신이 얻는 결과물을보십시오. –

관련 문제