Skip to content

Instantly share code, notes, and snippets.

@btiernay
Last active December 21, 2015 22:58
Show Gist options
  • Select an option

  • Save btiernay/6378567 to your computer and use it in GitHub Desktop.

Select an option

Save btiernay/6378567 to your computer and use it in GitHub Desktop.

Revisions

  1. btiernay revised this gist Sep 17, 2013. 1 changed file with 6 additions and 17 deletions.
    23 changes: 6 additions & 17 deletions facet-filter-with-nested-filter-fails.sh
    Original file line number Diff line number Diff line change
    @@ -1,43 +1,32 @@
    #!/bin/bash
    #
    # Description:
    # Example that shows how using a `facet_filter` with a `nested` filter fails to return facet terms.
    # Example that shows how using a `facet_filter` with a `nested` filter fails to return `nested` facet terms.

    # Remove index if it exists already
    curl -XDELETE http://localhost:9200/nested

    # Create a fresh index
    curl -XPOST http://localhost:9200/nested

    # Create a doubly nested mapping
    # Create a nested mapping
    curl -XPOST http://localhost:9200/nested/type/_mapping -d '
    {
    "type":{
    "properties":{
    "nested1":{
    "type":"nested",
    "properties":{
    "nested2":{
    "type":"nested",
    "properties":{}
    }
    }
    "type":"nested"
    }
    }
    }
    }'

    # Insert a document with a doubly nested doc
    # Insert a document with a nested doc
    curl -XPOST http://localhost:9200/nested/type/ -d '
    {
    "nested1":[
    {
    "x":1,
    "nested2":[
    {
    "y":2
    }
    ]
    "x":1
    }
    ]
    }'
    @@ -66,7 +55,7 @@ curl -XGET http://localhost:9200/nested/type/_search -d '
    "nested":"nested1",
    "facet_filter":{
    "nested":{
    "path":"nested1.nested2",
    "path":"nested1",
    "query":{
    "match_all":{}
    }
  2. btiernay revised this gist Aug 30, 2013. 1 changed file with 8 additions and 6 deletions.
    14 changes: 8 additions & 6 deletions facet-filter-with-nested-filter-fails.sh
    Original file line number Diff line number Diff line change
    @@ -3,13 +3,13 @@
    # Description:
    # Example that shows how using a `facet_filter` with a `nested` filter fails to return facet terms.

    # Clean
    # Remove index if it exists already
    curl -XDELETE http://localhost:9200/nested

    # Create index
    # Create a fresh index
    curl -XPOST http://localhost:9200/nested

    # Create doubly nested mapping
    # Create a doubly nested mapping
    curl -XPOST http://localhost:9200/nested/type/_mapping -d '
    {
    "type":{
    @@ -27,7 +27,7 @@ curl -XPOST http://localhost:9200/nested/type/_mapping -d '
    }
    }'

    # Insert document with a doubly nested doc
    # Insert a document with a doubly nested doc
    curl -XPOST http://localhost:9200/nested/type/ -d '
    {
    "nested1":[
    @@ -42,10 +42,12 @@ curl -XPOST http://localhost:9200/nested/type/ -d '
    ]
    }'

    # Ensure the previous doc is searchable
    # Ensure the previous document is searchable
    curl -XPOST 'http://localhost:9200/nested/_refresh'

    # This fails to return any terms:
    # Demonstrate that the following query with `facet_filter` and `nested` filter fails to return any terms. Note that
    # removing the `facet_filter` gives the expected results.
    #
    # Expected:
    # { ... "hits":{"total":1,"max_score":1.0,"hits":[]},"facets":{"nested1":{"_type":"terms","missing":0,"total":1,"other":0,"terms":[{"term":1,"count":1}]}}}
    # Actual:
  3. btiernay revised this gist Aug 30, 2013. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion facet-filter-with-nested-filter-fails.sh
    Original file line number Diff line number Diff line change
    @@ -42,7 +42,7 @@ curl -XPOST http://localhost:9200/nested/type/ -d '
    ]
    }'

    # Refresh
    # Ensure the previous doc is searchable
    curl -XPOST 'http://localhost:9200/nested/_refresh'

    # This fails to return any terms:
  4. btiernay revised this gist Aug 30, 2013. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion facet-filter-with-nested-filter-fails.sh
    Original file line number Diff line number Diff line change
    @@ -74,4 +74,4 @@ curl -XGET http://localhost:9200/nested/type/_search -d '
    }
    }'

    echo 'Done!'

  5. btiernay revised this gist Aug 30, 2013. 1 changed file with 5 additions and 0 deletions.
    5 changes: 5 additions & 0 deletions facet-filter-with-nested-filter-fails.sh
    Original file line number Diff line number Diff line change
    @@ -42,6 +42,9 @@ curl -XPOST http://localhost:9200/nested/type/ -d '
    ]
    }'

    # Refresh
    curl -XPOST 'http://localhost:9200/nested/_refresh'

    # This fails to return any terms:
    # Expected:
    # { ... "hits":{"total":1,"max_score":1.0,"hits":[]},"facets":{"nested1":{"_type":"terms","missing":0,"total":1,"other":0,"terms":[{"term":1,"count":1}]}}}
    @@ -70,3 +73,5 @@ curl -XGET http://localhost:9200/nested/type/_search -d '
    }
    }
    }'

    echo 'Done!'
  6. btiernay revised this gist Aug 30, 2013. 1 changed file with 1 addition and 19 deletions.
    20 changes: 1 addition & 19 deletions facet-filter-with-nested-filter-fails.sh
    Original file line number Diff line number Diff line change
    @@ -42,24 +42,6 @@ curl -XPOST http://localhost:9200/nested/type/ -d '
    ]
    }'

    # This returns terms:
    # { ... "hits":{"total":1,"max_score":1.0,"hits":[]},"facets":{"nested1":{"_type":"terms","missing":0,"total":1,"other":0,"terms":[{"term":1,"count":1}]}}}
    curl -XGET http://localhost:9200/nested/type/_search -d '
    {
    "size":0,
    "query":{
    "match_all":{}
    },
    "facets":{
    "nested1":{
    "terms":{
    "field":"x"
    },
    "nested":"nested1"
    }
    }
    }'

    # This fails to return any terms:
    # Expected:
    # { ... "hits":{"total":1,"max_score":1.0,"hits":[]},"facets":{"nested1":{"_type":"terms","missing":0,"total":1,"other":0,"terms":[{"term":1,"count":1}]}}}
    @@ -87,4 +69,4 @@ curl -XGET http://localhost:9200/nested/type/_search -d '
    }
    }
    }
    }'
    }'
  7. btiernay revised this gist Aug 30, 2013. 1 changed file with 23 additions and 1 deletion.
    24 changes: 23 additions & 1 deletion facet-filter-with-nested-filter-fails.sh
    Original file line number Diff line number Diff line change
    @@ -42,7 +42,29 @@ curl -XPOST http://localhost:9200/nested/type/ -d '
    ]
    }'

    # This fails to return any terms
    # This returns terms:
    # { ... "hits":{"total":1,"max_score":1.0,"hits":[]},"facets":{"nested1":{"_type":"terms","missing":0,"total":1,"other":0,"terms":[{"term":1,"count":1}]}}}
    curl -XGET http://localhost:9200/nested/type/_search -d '
    {
    "size":0,
    "query":{
    "match_all":{}
    },
    "facets":{
    "nested1":{
    "terms":{
    "field":"x"
    },
    "nested":"nested1"
    }
    }
    }'

    # This fails to return any terms:
    # Expected:
    # { ... "hits":{"total":1,"max_score":1.0,"hits":[]},"facets":{"nested1":{"_type":"terms","missing":0,"total":1,"other":0,"terms":[{"term":1,"count":1}]}}}
    # Actual:
    # { ... "hits":{"total":0,"max_score":null,"hits":[]},"facets":{"nested1":{"_type":"terms","missing":0,"total":0,"other":0,"terms":[]}}}
    curl -XGET http://localhost:9200/nested/type/_search -d '
    {
    "size":0,
  8. btiernay revised this gist Aug 30, 2013. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion facet-filter-with-nested-filter-fails.sh
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,7 @@
    #!/bin/bash
    #
    # Description:
    # Example that shows how using a `facet_filter` with a `nested` filter fails to execute.
    # Example that shows how using a `facet_filter` with a `nested` filter fails to return facet terms.

    # Clean
    curl -XDELETE http://localhost:9200/nested
  9. btiernay revised this gist Aug 30, 2013. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion facet-filter-with-nested-filter-fails.sh
    Original file line number Diff line number Diff line change
    @@ -42,7 +42,7 @@ curl -XPOST http://localhost:9200/nested/type/ -d '
    ]
    }'

    # This fails with QueryParsingException[[nested] [nested] failed to find nested object under path [nested2]];
    # This fails to return any terms
    curl -XGET http://localhost:9200/nested/type/_search -d '
    {
    "size":0,
  10. btiernay revised this gist Aug 29, 2013. 1 changed file with 1 addition and 2 deletions.
    3 changes: 1 addition & 2 deletions facet-filter-with-nested-filter-fails.sh
    Original file line number Diff line number Diff line change
    @@ -46,7 +46,6 @@ curl -XPOST http://localhost:9200/nested/type/ -d '
    curl -XGET http://localhost:9200/nested/type/_search -d '
    {
    "size":0,
    "fields":[],
    "query":{
    "match_all":{}
    },
    @@ -66,4 +65,4 @@ curl -XGET http://localhost:9200/nested/type/_search -d '
    }
    }
    }
    }'
    }'
  11. btiernay revised this gist Aug 29, 2013. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions facet-filter-with-nested-filter-fails.sh
    Original file line number Diff line number Diff line change
    @@ -53,7 +53,7 @@ curl -XGET http://localhost:9200/nested/type/_search -d '
    "facets":{
    "nested1":{
    "terms":{
    "field":"tags"
    "field":"x"
    },
    "nested":"nested1",
    "facet_filter":{
    @@ -66,4 +66,4 @@ curl -XGET http://localhost:9200/nested/type/_search -d '
    }
    }
    }
    }'
    }'
  12. btiernay revised this gist Aug 29, 2013. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions facet-filter-with-nested-filter-fails.sh
    Original file line number Diff line number Diff line change
    @@ -14,8 +14,8 @@ curl -XPOST http://localhost:9200/nested/type/_mapping -d '
    {
    "type":{
    "properties":{
    "list":{
    "nested1":"nested",
    "nested1":{
    "type":"nested",
    "properties":{
    "nested2":{
    "type":"nested",
    @@ -58,7 +58,7 @@ curl -XGET http://localhost:9200/nested/type/_search -d '
    "nested":"nested1",
    "facet_filter":{
    "nested":{
    "path":"nested2",
    "path":"nested1.nested2",
    "query":{
    "match_all":{}
    }
  13. btiernay revised this gist Aug 29, 2013. 1 changed file with 5 additions and 5 deletions.
    10 changes: 5 additions & 5 deletions facet-filter-with-nested-filter-fails.sh
    Original file line number Diff line number Diff line change
    @@ -17,14 +17,14 @@ curl -XPOST http://localhost:9200/nested/type/_mapping -d '
    "list":{
    "nested1":"nested",
    "properties":{
    "nested2":{
    "type":"nested",
    "properties":{}
    }
    "nested2":{
    "type":"nested",
    "properties":{}
    }
    }
    }
    }
    }
    }
    }'

    # Insert document with a doubly nested doc
  14. btiernay revised this gist Aug 29, 2013. 1 changed file with 8 additions and 8 deletions.
    16 changes: 8 additions & 8 deletions facet-filter-with-nested-filter-fails.sh
    Original file line number Diff line number Diff line change
    @@ -31,15 +31,15 @@ curl -XPOST http://localhost:9200/nested/type/_mapping -d '
    curl -XPOST http://localhost:9200/nested/type/ -d '
    {
    "nested1":[
    {
    "x" : 1,
    "nested2":[
    {
    "y" : 2
    }
    ]
    {
    "x":1,
    "nested2":[
    {
    "y":2
    }
    ]
    }
    ]
    ]
    }'

    # This fails with QueryParsingException[[nested] [nested] failed to find nested object under path [nested2]];
  15. btiernay revised this gist Aug 29, 2013. 1 changed file with 1 addition and 3 deletions.
    4 changes: 1 addition & 3 deletions facet-filter-with-nested-filter-fails.sh
    Original file line number Diff line number Diff line change
    @@ -60,9 +60,7 @@ curl -XGET http://localhost:9200/nested/type/_search -d '
    "nested":{
    "path":"nested2",
    "query":{
    "match_all":{
    }
    "match_all":{}
    }
    }
    }
  16. btiernay created this gist Aug 29, 2013.
    71 changes: 71 additions & 0 deletions facet-filter-with-nested-filter-fails.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,71 @@
    #!/bin/bash
    #
    # Description:
    # Example that shows how using a `facet_filter` with a `nested` filter fails to execute.

    # Clean
    curl -XDELETE http://localhost:9200/nested

    # Create index
    curl -XPOST http://localhost:9200/nested

    # Create doubly nested mapping
    curl -XPOST http://localhost:9200/nested/type/_mapping -d '
    {
    "type":{
    "properties":{
    "list":{
    "nested1":"nested",
    "properties":{
    "nested2":{
    "type":"nested",
    "properties":{}
    }
    }
    }
    }
    }
    }'

    # Insert document with a doubly nested doc
    curl -XPOST http://localhost:9200/nested/type/ -d '
    {
    "nested1":[
    {
    "x" : 1,
    "nested2":[
    {
    "y" : 2
    }
    ]
    }
    ]
    }'

    # This fails with QueryParsingException[[nested] [nested] failed to find nested object under path [nested2]];
    curl -XGET http://localhost:9200/nested/type/_search -d '
    {
    "size":0,
    "fields":[],
    "query":{
    "match_all":{}
    },
    "facets":{
    "nested1":{
    "terms":{
    "field":"tags"
    },
    "nested":"nested1",
    "facet_filter":{
    "nested":{
    "path":"nested2",
    "query":{
    "match_all":{
    }
    }
    }
    }
    }
    }
    }'