Skip to content

Instantly share code, notes, and snippets.

@jprante
Created October 22, 2013 11:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jprante/7099277 to your computer and use it in GitHub Desktop.
Save jprante/7099277 to your computer and use it in GitHub Desktop.
Demonstration of facets with multi_field
curl -XDELETE 'localhost:9200/test'
curl -XPUT 'localhost:9200/test/' -d '
{
"mappings" : {
"_default_": {
"properties" : {
"tags" : {
"type" : "multi_field",
"fields" : {
"tags" : { "type" : "string" },
"raw" : { "type" : "string", "index" : "not_analyzed" }
}
}
}
}
}
}
'
curl -XPUT 'localhost:9200/test/data/1' -d '
{
"tags" : [ "foo" ]
}
'
curl -XPUT 'localhost:9200/test/data/2' -d '
{
"tags" : [ "bar" ]
}
'
curl -XPUT 'localhost:9200/test/data/3' -d '
{
"tags" : [ "foo bar" ]
}
'
curl -XPUT 'localhost:9200/test/data/4' -d '
{
"tags" : [ "foo", "bar", "foo bar" ]
}
'
curl -XGET 'localhost:9200/test/_refresh'
curl -XGET 'localhost:9200/test/_search?pretty' -d '
{
"query" : {
"match": {
"tags": "foo"
}
}
}'
curl -XGET 'localhost:9200/test/_search?pretty' -d '
{
"query" : {
"match": {
"tags": "bar"
}
}
}'
curl -XGET 'localhost:9200/test/_search?pretty' -d '
{
"query" : {
"match": {
"tags": "bar"
}
},
"facets" : {
"f1" : {
"terms" : {
"field" : "tags.raw"
}
}
}
}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment