2017-01-16 4 views
0

私は古いプロジェクトを維持するために取り組んでいます。
私が使用しているelasticsearchのバージョンは1.7ですが、これは私の問題と関連していないと思います。フィルタリングされたクエリのクエリとコレクション

私はいくつかの教師の書類を持っている:

{ 
    "id": 244, 
    "degree": [], 
    "teacherDiplomaRelation": [], 
    "user": { 
    "enabled": true 
    }, 
    "teacherClassDisciplineRelation": [ 
    SEE BELOW 
} 

teacherClassDisciplineRelationは(私が持っているすべてのカップルのlevelTree /調教用)N回このフォーマットである

{ 
    "levelTree": { 
    "id": 34, 
    "label": "1st year of college", 
    "slugLastLevelDisplay": "college" 
    }, 
    "discipline": { 
    "id": 1, 
    "label": "Maths", 
    "slug": "maths" 
    }, 
    "cityLocation": "10.1010,10.1010" 
} 

今、私はすべてを取得したいです教師を有効にし、学問分野で数学を持つ。私のクエリは次のとおりです。

{ 
    "query": { 
    "filtered": { 
     "filter": { 
     "bool": { 
      "must": [ 
      { 
       "term": { 
       "user.enabled": true 
       } 
      }, 
      { 
       "term": { 
       "teacherClassDisciplineRelation.discipline.slug": "maths" 
       } 
      } 
      ] 
     } 
     } 
    } 
    }, 
    "size": { 
    "from": 0, 
    "size": 15 
    } 
} 

マッピング:

"teacherClassDisciplineRelation": { 
     "type": "nested", 
     "properties": { 
      "cityLocation": { 
      "type": "geo_point", 
      "store": true 
      }, 
      "discipline": { 
      "properties": { 
       "id": { 
       "type": "string", 
       "store": true 
       }, 
       "label": { 
       "type": "string", 
       "boost": 7.0, 
       "store": true, 
       "analyzer": "custom_analyzer" 
       }, 
       "slug": { 
       "type": "string", 
       "boost": 7.0, 
       "index": "not_analyzed", 
       "store": true, 
       "norms": { 
        "enabled": true 
       } 
       } 
      } 
      } 

問題:
"user.enabled": trueと私のクエリは私にいくつかの結果が得られ、 は"teacherClassDisciplineRelation.discipline.slug": "maths"と私のクエリはいつも私に0結果を与えますが、私は」インデックスをチェックしました私はいくつかの結果が必要です

私はelasticsearchの新作ですが、なぜ私の結果が常に0であるかを知ることができません。 理由は何ですか?

+0

マッピングを共有してください。 'GET index_name/type_name/_mapping' – Richa

+0

@リチャ私はちょうどそれを追加しました – goto

答えて

1

teacherClassDisciplineRelationはネストされたフィールドです。 Nested Queryを使用する必要があります。

{ 
"query": { 
    "bool": { 
    "must": [ 
     { 
      "nested": { 
       "path": "teacherClassDisciplineRelation", 
       "query": { 
       "term": { 
        "teacherClassDisciplineRelation.discipline.slug": { 
         "value": "maths" 
        } 
       } 
       } 
      } 
     }, 
     { 
      "term": { 
       "user.enabled": true 
      } 
      } 
     ] 
    } 
    } 
} 

+0

ありがとう!ネストされたクエリの代わりにネストされたフィルタを使用する必要がありましたが、あなたの例は私をうまく助けます。特に道は私には不明でした。 – goto

+0

お手伝いします! – Richa

関連する問題