{"id":809,"date":"2021-08-20T02:21:32","date_gmt":"2021-08-20T02:21:32","guid":{"rendered":"https:\/\/bruceng.com\/dev\/?p=809"},"modified":"2021-08-20T02:21:59","modified_gmt":"2021-08-20T02:21:59","slug":"filtering-multiple-condition-with-nested-queries-in-elasticsearch","status":"publish","type":"post","link":"https:\/\/bruceng.com\/dev\/?p=809","title":{"rendered":"Filtering by multiple conditions with nested queries in Elasticsearch"},"content":{"rendered":"\n<p>All bool queries are evaluated on a single document.<\/p>\n\n\n\n<p>So if you have an index like this<\/p>\n\n\n\n<p>Products= {<\/p>\n\n\n\n<p>Fields: { Name: string; Value: int; }[];<\/p>\n\n\n\n<p>}<\/p>\n\n\n\n<p>And you want to find products with field &#8220;Price&#8221; between 10 and 20, and field &#8220;Discount&#8221; between 0 and 5, you can use the following query<\/p>\n\n\n\n<p>bool: {<\/p>\n\n\n\n<p>must: [<\/p>\n\n\n\n<p>{nested: { \/\/nested query to find products with price from 10 to 20},<\/p>\n\n\n\n<p>{nested: { \/\/nested query to find products with Discount from 0 to 5}<\/p>\n\n\n\n<p>]<\/p>\n\n\n\n<p>}<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>It looks quite hard to follow.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>All bool queries are evaluated on a single document. So if you have an index like this Products= { Fields: { Name: string; Value: int; }[]; } And you want to find products with field &#8220;Price&#8221; between 10 and 20, and field &#8220;Discount&#8221; between 0 and 5, you can use the following query bool: { &hellip; <a href=\"https:\/\/bruceng.com\/dev\/?p=809\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Filtering by multiple conditions with nested queries in Elasticsearch&#8221;<\/span><\/a><\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5,14],"tags":[116,115],"class_list":["post-809","post","type-post","status-publish","format-standard","hentry","category-problems","category-tips-and-tricks","tag-elasticsearch","tag-nosql"],"_links":{"self":[{"href":"https:\/\/bruceng.com\/dev\/index.php?rest_route=\/wp\/v2\/posts\/809","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/bruceng.com\/dev\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/bruceng.com\/dev\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/bruceng.com\/dev\/index.php?rest_route=\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/bruceng.com\/dev\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=809"}],"version-history":[{"count":3,"href":"https:\/\/bruceng.com\/dev\/index.php?rest_route=\/wp\/v2\/posts\/809\/revisions"}],"predecessor-version":[{"id":812,"href":"https:\/\/bruceng.com\/dev\/index.php?rest_route=\/wp\/v2\/posts\/809\/revisions\/812"}],"wp:attachment":[{"href":"https:\/\/bruceng.com\/dev\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=809"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/bruceng.com\/dev\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=809"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/bruceng.com\/dev\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=809"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}