2016-07-04 3 views
1

내 elasticsearch db에서 중첩 된 문서의 필드를 검색하고 싶습니다.elasticsearch.js 및 각도를 사용하여 Elasticsearch에서 중첩 된 개체를 검색하는 방법

curl -X GET 'http://localhost:9200/jira-dev/_search?pretty=true' -d ' 
{ 
"_source" : false, 
"query" : { 
    "nested" : { 
     "path" : "issues", 
     "query" : { 
      "bool": { 
      "should": [     
       { 
       "wildcard":{ 
        "issues.fields.description":"*migrate*" 
       } 
       }, 
       { 
       "wildcard":{ 
        "issues.fields.comment.comments.body":"*autodeploy*" 
       } 
       } 
      ] 
      }    
     }, 
     "inner_hits" : {"size": 5000} 
     } 
    } 
}' 

하지만이 방법으로 elasticsearch.js를 사용하여 전화를 할 때, 그것이 어떤 결과를 얻을하지 않습니다 :

나는 중첩 된 객체의 필드 (점점 (10) 내부 안타를) 검색하려면 다음 명령을 사용하여
client.search({ 
    index: 'jira-dev/', 
    type: 'jira', 
    body: { 
     query: { 
      nested : { 
       path : "issues", 
       query : { 
        bool: { 
         should: [     
         { 
          wildcard:{ 
           "issues.fields.description":"*migrate*" 
          } 
         }, 
         { 
          wildcard:{ 
           "issues.fields.comment.comments.body":"*autodeploy*" 
          } 
         } 
         ] 
        }    
       }, 
       inner_hits : {size: 5000} 
      } 
      } 
     } 
}).then(function (resp) { 
    var hits = resp.hits.totals; 
    console.log('works'); 
}, function (err) { 
    console.log('epic fail'); 
    console.trace(err.message); 
}); 

내가 사용하는 구문이 올바르지 않다고 생각하지만 elasticsearch.js를 사용하여 중첩 쿼리의 예를 찾지 못했습니다.

미리 감사드립니다.

편집 : 요청 같이

, 문서의 구성되어 다음

curl -X POST 'http://localhost:9200/jira-dev/' -d '{ 
    "mappings" : { 
     "jira" : { 
      "properties" : { 
       "expand" : {"type" : "string"}, 
       "startAt" : {"type" : "integer"}, 
       "maxResults" : {"type" : "integer"}, 
       "total" : {"type" : "integer"}, 
       "issues" : { 
        "type" : "nested", 
        "include_in_parent" : false, 
        "properties" : { 
         "created" : {"type" : "date", "format" : "date_hour_minute_second_fraction"} 
        } 
       } 
      } 
     } 
    }, 
    "settings" : { 
     "number_of_shards" : 5, 
     "number_of_replicas" : 1 
    } 
}' 

및 예 : 마지막

{ 

    "_index": "jira-dev", 
    "_type": "jira", 
    "_id": "1", 
    "_version": 1, 
    "_score": 1, 
    "_source": { 
     "expand": "schema,names", 
     "startAt": 0, 
     "maxResults": 1000, 
     "total": 604, 
     "issues": [ 
      { 

       "key": "STACK-1", 
       "fields": { 
        "summary": "A nice summary", 
        "created": "2016-06-28T09:45:32.000+0000", 
        "description": null,      
        "comment": { 
         "startAt": 0, 
         "maxResults": 1, 
         "total": 1, 
         "comments": [ 
          { 
           "self": url", 
           "id": "30293", 
           "author": { 
            "name": "stack_overflow", 
            "key": "stack_overflow" 
           }, 
           "body": "Following epic has been created: url", 
           "updateAuthor": { 
            "name": "stack_overflow", 
            "key": "stack_overflow", 
            "timeZone": "Europe/Madrid" 
           }, 
           "created": "2016-03-04T10:09:11.000+0000", 
           "updated": "2016-03-04T10:09:11.000+0000" 
          } 
         ] 
        } 
       } 
      } 
     ] 
    } 
} 
+0

문서의 구조가 어떻게 보이는지 예를 들려 줄 수 있습니까? –

+0

확실히 예를 들어 추가했습니다. –

답변

0

는이 문제를 건너 I는 미들웨어를 사용했다 각도와 탄성 사이의 서버. 이 서버는 python 서버이며 curl을 통해 elasticsearch에서 GET/POST를 쉽게 수행 할 수 있습니다.

또한 Angular (html GET)에서 컬을 직접 사용하려했으나 관습에 따라 html 서버는 GET 청원서의 데이터를 무시할 수 있습니다. 따라서 Angular의 말풍선을 통해 탄력성 탄원서를 제출하는 것은 불가능했습니다.