{"action":"created","issue":{"url":"https://api.github.com/repos/danpaz/bodybuilder/issues/183","repository_url":"https://api.github.com/repos/danpaz/bodybuilder","labels_url":"https://api.github.com/repos/danpaz/bodybuilder/issues/183/labels{/name}","comments_url":"https://api.github.com/repos/danpaz/bodybuilder/issues/183/comments","events_url":"https://api.github.com/repos/danpaz/bodybuilder/issues/183/events","html_url":"https://github.com/danpaz/bodybuilder/issues/183","id":325879520,"node_id":"MDU6SXNzdWUzMjU4Nzk1MjA=","number":183,"title":"Cannot build valid 'nested' queries in filter context","user":{"login":"cricketts","id":4120195,"node_id":"MDQ6VXNlcjQxMjAxOTU=","avatar_url":"https://avatars1.githubusercontent.com/u/4120195?v=4","gravatar_id":"","url":"https://api.github.com/users/cricketts","html_url":"https://github.com/cricketts","followers_url":"https://api.github.com/users/cricketts/followers","following_url":"https://api.github.com/users/cricketts/following{/other_user}","gists_url":"https://api.github.com/users/cricketts/gists{/gist_id}","starred_url":"https://api.github.com/users/cricketts/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cricketts/subscriptions","organizations_url":"https://api.github.com/users/cricketts/orgs","repos_url":"https://api.github.com/users/cricketts/repos","events_url":"https://api.github.com/users/cricketts/events{/privacy}","received_events_url":"https://api.github.com/users/cricketts/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2018-05-23T21:26:22Z","updated_at":"2018-06-14T16:45:11Z","closed_at":null,"author_association":"NONE","body":"From what I can tell, it's not possible to perform a nested query inside of a filter context with BodyBuilder:\r\n\r\n```javascript\r\nbodybuilder().orFilter('nested', 'path', 'my_path', b => \r\n  b.query('term', 'my_path.my_field', 'my_value')\r\n)\r\n```\r\n\r\nThis doesn't work because `b.query` does not exist, and instead only various filter functions are available. I believe this has to do with being in the \"filter context\" because of the outer `orFilter()`.\r\n\r\nIf I try to use `filter`, however:\r\n\r\n```javascript\r\nbodybuilder().orFilter('nested', 'path', 'my_path', b => \r\n  b.filter('term', 'my_path.my_field', 'my_value')\r\n)\r\n```\r\n\r\nThis results in a `400 Bad Request` from Elasticsearch because filters inside of a nested field is not supported. I am running against Elasticsearch v6.2.\r\n\r\nIf I use an `orQuery` at the top-level this works fine:\r\n\r\n```javascript\r\nbodybuilder().orQuery('nested', 'path', 'my_path', b => \r\n  b.query('term', 'my_path.my_field', 'my_value')\r\n)\r\n```\r\n\r\nHowever this doesn't work for me because I want my boolean condition to live in the filter context with my other conditions and it's cheaper to perform.\r\n"},"comment":{"url":"https://api.github.com/repos/danpaz/bodybuilder/issues/comments/397361805","html_url":"https://github.com/danpaz/bodybuilder/issues/183#issuecomment-397361805","issue_url":"https://api.github.com/repos/danpaz/bodybuilder/issues/183","id":397361805,"node_id":"MDEyOklzc3VlQ29tbWVudDM5NzM2MTgwNQ==","user":{"login":"AncientSwordRage","id":5961746,"node_id":"MDQ6VXNlcjU5NjE3NDY=","avatar_url":"https://avatars3.githubusercontent.com/u/5961746?v=4","gravatar_id":"","url":"https://api.github.com/users/AncientSwordRage","html_url":"https://github.com/AncientSwordRage","followers_url":"https://api.github.com/users/AncientSwordRage/followers","following_url":"https://api.github.com/users/AncientSwordRage/following{/other_user}","gists_url":"https://api.github.com/users/AncientSwordRage/gists{/gist_id}","starred_url":"https://api.github.com/users/AncientSwordRage/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/AncientSwordRage/subscriptions","organizations_url":"https://api.github.com/users/AncientSwordRage/orgs","repos_url":"https://api.github.com/users/AncientSwordRage/repos","events_url":"https://api.github.com/users/AncientSwordRage/events{/privacy}","received_events_url":"https://api.github.com/users/AncientSwordRage/received_events","type":"User","site_admin":false},"created_at":"2018-06-14T16:45:11Z","updated_at":"2018-06-14T16:45:11Z","author_association":"NONE","body":"I have been trying to follow this issue (as I have a similar one) and I cannot get\r\n```\r\nbodybuilder().orFilter('nested', {\r\n  path: 'my_path',\r\n  ...bodybuilder().query('term', 'my_path.my_field', 'my_value').build()\r\n})\r\n```\r\nto run in the repl at https://bodybuilder.js.org/ is that expected or is it something we can fix?"}}
{"actor":{"display_login":"AncientSwordRage"}}