2013-12-18 5 views
2

내가 좋아하는 매핑을 가지고있다. 각 사람은 여러 가지 교육을받을 수 있습니다. 내가 원하는 것은 "2012"에서 "SFU"를 졸업 한 사람들을 검색하는 것입니다. 내가 필터링 된 검색 사용하고 있음을하려면 : 교육의탄성 검색 여러 용어는

"filtered": { 
    "filter": { 
     "and": [ 
      { 
       "term": { 
       "educations.university": "SFU" 
       } 
      }, 
      { 
       "term": { 
       "educations.graduation_year": "2012" 
       } 
      } 
     ] 
    } 

그러나이 쿼리가하는 일은 "SFU"이 문서를 찾을 수 있습니다와 "2012", 그래서이 문서가 일치합니다, 잘못이다 :

educations[0] = {"university": "SFU", "graduation_year": 2000} 
educations[1] = {"university": "UBC", "graduation_year": 2012} 

어쨌든 각 교육에서 두 용어를 모두 필터링 할 수 있습니까?

답변

2

educations에 중첩 형식을 정의하고 필터를 사용하려면 중첩 필터를 사용해야합니다. 그렇지 않으면 Elasticsearch가 내부 개체를 내부적으로 단일 개체로 평탄화하고 잘못된 결과를 반환합니다. 당신은 세부 사항 explainations 및 샘플 여기를 참조 할 수 있습니다 :

http://www.elasticsearch.org/blog/managing-relations-inside-elasticsearch/ http://www.spacevatican.org/2012/6/3/fun-with-elasticsearch-s-children-and-nested-documents/