Created
September 5, 2012 19:54
-
-
Save anonymous/3643513 to your computer and use it in GitHub Desktop.
Working ElasticSearch dynamic template
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
curl -XPUT localhost:9200/test | |
curl -XPUT http://localhost:9200/test/data/_mapping -d '{ | |
"data" : { | |
"dynamic_templates" : [ | |
{ | |
"meta_raw_template" : { | |
"path_match" : "*meta_raw.*", | |
"mapping" : { | |
"index" : "not_analyzed", | |
"store" : "yes" | |
} } }, | |
{ | |
"meta_template" : { | |
"path_match" : "*meta.*", | |
"mapping" : { | |
"index" : "analyzed", | |
"store" : "yes" | |
} } } | |
] | |
} } | |
' | |
curl -XPUT http://localhost:9200/test/data/1 -d '{ | |
"meta" : { | |
"byline" : "Greg Brown" | |
}, | |
"meta_raw" : { | |
"byline" : "Greg Brown" | |
} | |
}' | |
curl -XPOST http://localhost:9200/test/_refresh | |
curl -XGET http://localhost:9200/test/_search?pretty -d '{ | |
size : 10, | |
query : { | |
filtered : { | |
query : { | |
query_string: { | |
fields: [ "meta.byline" ], | |
query: "*", | |
default_operator: "AND" | |
} }, | |
filter : { | |
match_all: { } | |
} | |
} }, | |
facets : { | |
meta : { | |
terms : { | |
field : "meta.byline", | |
size : 10 | |
} | |
}, | |
meta_raw : { | |
terms : { | |
field : "meta_raw.byline", | |
size : 10 | |
} | |
} | |
} | |
}' | |
//results | |
{ | |
"took" : 1, | |
"timed_out" : false, | |
"_shards" : { | |
"total" : 5, | |
"successful" : 5, | |
"failed" : 0 | |
}, | |
"hits" : { | |
"total" : 1, | |
"max_score" : 1.0, | |
"hits" : [ { | |
"_index" : "test", | |
"_type" : "data", | |
"_id" : "1", | |
"_score" : 1.0, "_source" : { | |
"meta" : { | |
"byline" : "Greg Brown" | |
}, | |
"meta_raw" : { | |
"byline" : "Greg Brown" | |
} | |
} | |
} ] | |
}, | |
"facets" : { | |
"meta" : { | |
"_type" : "terms", | |
"missing" : 0, | |
"total" : 2, | |
"other" : 0, | |
"terms" : [ { | |
"term" : "greg", | |
"count" : 1 | |
}, { | |
"term" : "brown", | |
"count" : 1 | |
} ] | |
}, | |
"meta_raw" : { | |
"_type" : "terms", | |
"missing" : 0, | |
"total" : 1, | |
"other" : 0, | |
"terms" : [ { | |
"term" : "Greg Brown", | |
"count" : 1 | |
} ] | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment