Skip to content

Instantly share code, notes, and snippets.

@clintongormley
Created March 22, 2013 12:46
Show Gist options
  • Save clintongormley/5220985 to your computer and use it in GitHub Desktop.
Save clintongormley/5220985 to your computer and use it in GitHub Desktop.

Index two docs:

curl -XPUT 'http://127.0.0.1:9200/test/test/1?pretty=1'  -d '
{
   "text" : "foo bar"
}
'

curl -XPUT 'http://127.0.0.1:9200/test/test/2?pretty=1'  -d '
{
   "text" : "baz"
}
'

Check the terms facet:

curl -XGET 'http://127.0.0.1:9200/test/test/_search?pretty=1'  -d '
{
   "facets" : {
      "text" : {
         "terms" : {
            "all_terms" : 1,
            "field" : "text"
         }
      }
   },
   "size" : 0
}
'

# {
#    "hits" : {
#       "hits" : [],
#       "max_score" : 1,
#       "total" : 2
#    },
#    "timed_out" : false,
#    "_shards" : {
#       "failed" : 0,
#       "successful" : 5,
#       "total" : 5
#    },
#    "facets" : {
#       "text" : {
#          "other" : 0,
#          "terms" : [
#             {
#                "count" : 1,
#                "term" : "foo"
#             },
#             {
#                "count" : 1,
#                "term" : "baz"
#             },
#             {
#                "count" : 1,
#                "term" : "bar"
#             }
#          ],
#          "missing" : 0,
#          "_type" : "terms",
#          "total" : 3
#       }
#    },
#    "took" : 3
# }

Delete one doc:

curl -XDELETE 'http://127.0.0.1:9200/test/test/1?pretty=1' 

The terms no longer show up in the terms facet:

curl -XGET 'http://127.0.0.1:9200/test/test/_search?pretty=1'  -d '
{
   "facets" : {
      "text" : {
         "terms" : {
            "all_terms" : 1,
            "field" : "text"
         }
      }
   },
   "size" : 0
}
'

# {
#    "hits" : {
#       "hits" : [],
#       "max_score" : 1,
#       "total" : 1
#    },
#    "timed_out" : false,
#    "_shards" : {
#       "failed" : 0,
#       "successful" : 5,
#       "total" : 5
#    },
#    "facets" : {
#       "text" : {
#          "other" : 0,
#          "terms" : [
#             {
#                "count" : 1,
#                "term" : "baz"
#             }
#          ],
#          "missing" : 0,
#          "_type" : "terms",
#          "total" : 1
#       }
#    },
#    "took" : 1
# }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment