Skip to content

Instantly share code, notes, and snippets.

@barseghyanartur
Forked from zwrss/mapping.sh
Created May 23, 2016 07:40
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 barseghyanartur/a931d14c5e48f040a398f80313e95382 to your computer and use it in GitHub Desktop.
Save barseghyanartur/a931d14c5e48f040a398f80313e95382 to your computer and use it in GitHub Desktop.
Mappings for elasticsearch not nested stuff
#!/bin/sh
echo
curl -XDELETE 'http://localhost:9200/items'
echo
curl -XPUT 'localhost:9200/items' -d '
{
"mappings" : {
"Item" : {
"dynamic" : false,
"properties" : {
"id" : { "type" : "string", "index" : "not_analyzed" },
"name" : { "type" : "string", "index" : "not_analyzed" },
"price" : { "type" : "double", "index" : "not_analyzed" },
"type" : { "type" : "string", "index" : "not_analyzed" },
"characteristics" : { "type" : "string", "index" : "not_analyzed" }
}
}
}
}
'
echo
curl -XPOST 'http://localhost:9200/items/Item' -d '
{
"id" : "id1",
"name" : "Sonz flatscreen",
"price" : 200.0,
"type" : "TV",
"characteristics" : [
"warranty_3 years",
"screen size_32 in",
"display_LCD"
]
}
'
echo
curl -XPOST 'http://localhost:9200/items/Item' -d '
{
"id" : "id1",
"name" : "Sonz flatscreen",
"price" : 200.0,
"type" : "TV",
"characteristics" : [
"warranty_2 years",
"screen size_32 in",
"display_Plasma"
]
}
'
echo
curl -XPOST 'http://localhost:9200/items/Item' -d '
{
"id" : "id1",
"name" : "Sonz bigbum",
"price" : 200.0,
"type" : "TV",
"characteristics" : [
"warranty_3 years",
"screen size_32 in",
"display_CRT",
"speakers_5.1"
]
}
'
echo
curl -XPOST 'http://localhost:9200/items/Item' -d '
{
"id" : "id1",
"name" : "Shark plazmos",
"price" : 300.0,
"type" : "TV",
"characteristics" : [
"warranty_2 years",
"screen size_54 in",
"display_Plasma"
]
}
'
echo
curl -XPOST 'http://localhost:9200/items/Item' -d '
{
"id" : "id1",
"name" : "Sonz player",
"price" : 150.0,
"type" : "DVD Player",
"characteristics" : [
"warranty_3 years"
]
}
'
echo
curl -XPOST 'http://localhost:9200/items/Item' -d '
{
"id" : "id1",
"name" : "Shark player",
"price" : 200.0,
"type" : "DVD Player",
"characteristics" : [
"warranty_3 years"
]
}
'
echo
curl -XPOST 'http://localhost:9200/items/Item' -d '
{
"id" : "id1",
"name" : "Sonz HiFi",
"price" : 200.0,
"type" : "HIFI",
"characteristics" : [
"warranty_3 years",
"speakers_5.1"
]
}
'
echo
#!/bin/sh
curl -X POST 'localhost:9200/items/_search?pretty=true' -d '
{
"query" : {
"match_all" : {}
},
"filter" : {
"and" : [
{ "term" : { "type" : "TV" } },
{ "term" : { "characteristics" : "warranty_3 years" } },
{ "term" : { "characteristics" : "screen size_32 in" } }
]
},
"facets" : {
"screen size" : {
"terms" : {
"field" : "characteristics",
"regex" : "screen size_.*",
"regex_flags" : "DOTALL"
},
"facet_filter" : {
"and" : [
{ "term" : { "type" : "TV" } },
{ "term" : { "characteristics" : "warranty_3 years" } }
]
}
},
"warranty" : {
"terms" : {
"field" : "characteristics",
"regex" : "warranty_.*",
"regex_flags" : "DOTALL"
},
"facet_filter" : {
"and" : [
{ "term" : { "type" : "TV" } },
{ "term" : { "characteristics" : "screen size_32 in" } }
]
}
},
"type" : {
"terms" : { "field" : "type" },
"facet_filter" : {
"and" : [
{ "term" : { "characteristics" : "warranty_3 years" } },
{ "term" : { "characteristics" : "screen size_32 in" } }
]
}
},
"name" : {
"terms" : { "field" : "name" },
"facet_filter" : {
"and" : [
{ "term" : { "type" : "TV" } },
{ "term" : { "characteristics" : "warranty_3 years" } },
{ "term" : { "characteristics" : "screen size_32 in" } }
]
}
}
}
}
'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment