Skip to content

Instantly share code, notes, and snippets.

@Halama
Created May 27, 2015 11:42
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 Halama/c51fd28eef298d304e9d to your computer and use it in GitHub Desktop.
Save Halama/c51fd28eef298d304e9d to your computer and use it in GitHub Desktop.
Elastic search nested filter
POST /activity
{"settings" : {
"number_of_shards" : 1
},
"mappings" : {
"activity" : {
"properties": {
"id": {
"type": "long"
},
"target": {
"type": "nested",
"properties": {
"name": {"type": "string", "index": "not_analyzed"},
"value": {"type": "string", "index": "not_analyzed"}
}
}
}
}
}
}
POST /activity/activity/123
{
"id": 123,
"target": [
{
"name": "component",
"value": "ex-generic"
},
{
"name": "config",
"value": "123"
}
]
}
POST /activity/activity/125
{
"id": 125,
"target": [
{
"name": "component",
"value": "ex-generic"
},
{
"name": "config",
"value": "dalsi"
}
]
}
POST /activity/activity/126
{
"id": 126,
"target": [
{
"name": "component",
"value": "ex-google-drive"
},
{
"name": "config",
"value": "dalsi"
}
]
}
POST /activity/activity/_search
{
"query": {
"filtered": {
"query": {"match_all": {}},
"filter": {
"bool": {
"must": [
{
"nested": {
"path": "target",
"filter": {
"bool": {
"must": [
{
"term": {
"target.name": "component"
}
},
{
"term": {
"target.value": "ex-generic"
}
}
]
}
}
}
},
{
"nested": {
"path": "target",
"filter": {
"bool": {
"must": [
{
"term": {
"target.name": "config"
}
},
{
"term": {
"target.value": "dalsi"
}
}
]
}
}
}
}
]
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment