私はelasticsearchを初めて使用しており、必要なクエリを作成する際に問題があります。私は、クエリ、フィルタリング、クエリをbooling、およびネストされたオブジェクトを読んできましたが、私はまだ少しぼんやりしています。私はelasticsearchのためのPHPコンポーザーパッケージを使用していますが、私はそれが私の設定でもっと問題だと思います。エラスティックサーチ:複数の配列のネストされたオブジェクトをフィルタリングします
私は、オブジェクトが持つプロパティとそのネストされたオブジェクトが持つプロパティに基づいてオブジェクトをフィルタリングしようとしています。次のように私が持っているでしょう
例のオブジェクトは、次のとおりです。
{
'id' : '1',
'title' : 'real catchy title',
'description' : 'description goes here',
'content' : [
'id' : '1',
'title' : 'foo',
'subtitle' : 'bar',
'text' : 'legit full text',
'sidebar' : 'whatever yo!',
],
'pages' : '12',
'departments' : [
{
'id' : '1',
'name' : 'foo',
'description' : 'lorem ipsum'
},
{
'id' : '2',
'name' : 'bar',
'description' : 'lorem ipsum'
}
]
'themes' : [
{
'id' : '1',
'name' : 'foo',
'description' : 'lorem ipsum',
'month' : '3'
},
{
'id' : '2',
'name' : 'bar',
'description' : 'lorem ipsum',
'month' : '2'
}
]
}
を、私はページが指定した番号と一致した場合に基づいて、それに基づいてフィルタリングしようとしている、そしてそれは、特定の部門で部門を持っている場合idとテーマIDを持つテーマを持っています。
これを行うために、私は私のマッピングを持っている:
[
'index' : ,'reusable_content'
'body' => [
'mappings' => [
'reusable_content' => [
'_all' => ['analyzer' => 'english'],
'properties' => [
'departments' => [
'type' => 'nested',
"include_in_parent" => true
],
'themes' => [
'type' => 'nested',
"include_in_parent" => true
]
]
]
]
]
]
私はそれを挿入してから、私はいくつかのエントリを追加した後、それを照会するにはいくつかの方法を試してみました。
私はブールネストされたフィルタを使用して試してみた:
[
'index' => $this->getIndexName(),
'type' => 'reusable_content',
'body' => [
'query' => [
'filtered' => [
'query' => ['match_all' => []],
'filter' => [
'bool' => [
'should' => [
'nested' => [
'path' => 'themes',
'filter' => [
'bool' => [
'must' => [
'term' => [
'id' => $themeId
]
]
]
]
],
'nested' => [
'path' => 'departments',
'filter' => [
'bool' => [
'must' => [
'term' => [
'id' => $departmentId
]
]
]
]
]
]
]
]
]
]
]
]
が、これは結果を返しません。
私もフィルタを照会しなければならないブール値のような単純な方法を使用して試してみた:、これは主に働く
[
'index' => $this->getIndexName(),
'type' => 'reusable_content',
'body' => [
'query' => [
'filtered' => [
'query' => ['match_all' => []],
'filter' => [
'bool' => [
'must' => ['term' => ['pages' => $pages]],
'must' => ['term' => ['departments.id' => $departmentId]],
'must' => ['term' => ['themes.id' => $themeId]],
]
]
]
]
]
]
しかし、それは私が唯一のフィルタの'must' => ['term' => ['pages' => $pages]],
を持っているがあれば、フィルタリングページを無視しますIDフィールドを無視すると、ページフィルタが機能します。
私は弾力的な検索にはまったく新しいので、何か変わった仮定をしたり、間違ったことをしている場合は教えてください。さらに詳しい情報が必要な場合はお問い合わせください。
興味深い。しかし、私の場合、ページとIDは常に数字になるでしょう。私はそれで奇妙なトークンの変換を期待していないだろう。また、私はそれらのいずれかを個別に使用すると動作しますが、3つすべてを組み合わせようとすると、そうでない場合があります。 – samuraiseoul
数値が整数になるように設定していますか? – rajat