2014-11-20 5 views
1

int 배열 유형의 필드에이 문제가 있습니다. Node.js에 aws-sdk를 사용하여 CloudSearchDomain.uploadDocuments() 메소드를 통해 문서를 제출합니다. 합니다 (searchContent 변수) 문서의 JSON는 노드 처리에서 생성되고, 그때 사용AWS CloudSearch : [fieldname]의 값은 JSON 배열 또는 객체 일 수 없습니다.

var params = { 
    contentType: 'application/json', 
    documents: JSON.stringify([searchContent]) 
}; 
csd.uploadDocuments(params, function(err, data){ 
    ...(callback process)... 
}); 

을 비도 캐릭터 라인 목적은 다음과 같다 searchContent :

{ id: 1, 
    type: 'Product', 
    hash_type_id: 'Product-1', 
    name: 'Test product', 
    description: 'A test product', 
    category: [ 2 ], 
    content: '<some text here>', 
    state: [ 1 ], 
    hash_all: '<some text>' 
} 

그리고 다음과 같이 문자열 화됩니다 :오류가 발생했습니다 :

[{"id":1,"type":"Product","hash_type_id":"Product-1","name":"Test product","description":"A test product","content":" <some text>","category":[2],"state":[1],"hash_all":"<some text>"}] 
{ 
    "message": "{ [\"The value of category cannot be a JSON array or object\"] }", 
    "code": "DocumentServiceException", 
    "time": "2014-11-20T01:24:27.499Z", 
    "statusCode": 400, 
    "retryable": false 
} 

언급 한 바와 같이, 카테고리 필드는 int- 어레이 타입이다. 왜 내가이 메시지를 듣겠습니까?

업데이트 : 정확히 동일한 결과를 가진 범주 필드에 대해 형식화 된 배열 (Int16Array)을 사용해 보았습니다.

답변

5

문서를 일괄 처리 매개 변수로 묶어야합니다. 일괄 적으로 각 문서의 형식은 다음과 같아야합니다.

{ 
    type: "add|update|delete", 
    id: "Unique ID", 
    fields: Document JSON here 
} 

이 문서는 단일 문서 일지라도 배열로되어 있어야합니다. 따라서이 질문에 대한 문서의 JSON은 다음과 같습니다.

{ 
    type: "add", 
    id: "Product-1", 
    fields: { id: 1, 
    type: 'Product', 
    hash_type_id: 'Product-1', 
    name: 'Test product', 
    description: 'A test product', 
    category: [ 2 ], 
    content: '<some text here>', 
    state: [ 1 ], 
    hash_all: '<some text>' 
    } 
} 
+1

업로드 된 문서에 대한 AWS CloudSearch 지원 '업데이트'유형이 표시되지 않습니다. 'add'와'delete' 타입 만 있습니다. 정의 된'id'를 가진 문서가 이미 존재한다면 덮어 씌여 질 것입니다. Amazon Docs : http://docs.aws.amazon.com/cloudsearch/latest/developerguide/preparing-data.html#adding-documents –

+0

나는 여전히 같은 문제에 직면 해있다. 누군가가 도와 줄 수 있습니까? http://stackoverflow.com/questions/43945038/aws-cloudsearch-upload-json-value-tag-cannot-be-array-or-object – Atrix1987