Skip to content

Instantly share code, notes, and snippets.

@jprante
Created January 8, 2015 10:51
Show Gist options
  • Select an option

  • Save jprante/df600541e4b776f3f7ef to your computer and use it in GitHub Desktop.

Select an option

Save jprante/df600541e4b776f3f7ef to your computer and use it in GitHub Desktop.
Nested query, path, repeated field names
curl -XDELETE 'localhost:9200/test'
curl -XPUT 'localhost:9200/test'
curl -XPUT 'localhost:9200/test/virksomhed/_mapping' -d '
{
"properties": {
"Vrvirksomhed": {
"properties": {
"cvrNummer": {
"type": "string"
},
"dataAdgang": {
"type": "long"
},
"enhedsNummer": {
"type": "long"
},
"enhedstype": {
"type": "string"
},
"fejlRegistreret": {
"type": "boolean"
},
"fejlVedIndlaesning": {
"type": "boolean"
},
"harFremtidigAendring": {
"type": "boolean"
},
"livsforloeb": {
"properties": {
"gyldigFra": {
"format": "dateOptionalTime",
"type": "date"
},
"gyldigTil": {
"format": "dateOptionalTime",
"type": "date"
},
"sidstOpdateret": {
"format": "dateOptionalTime",
"type": "date"
}
},
"type": "nested"
},
"samtId": {
"type": "long"
},
"sidstIndlaest": {
"format": "dateOptionalTime",
"type": "date"
},
"sidstOpdateret": {
"format": "dateOptionalTime",
"type": "date"
},
"virksomhedsstatus": {
"properties": {
"gyldigFra": {
"format": "dateOptionalTime",
"type": "date"
},
"gyldigTil": {
"format": "dateOptionalTime",
"type": "date"
},
"sidstOpdateret": {
"format": "dateOptionalTime",
"type": "date"
},
"status": {
"type": "string"
}
},
"type": "nested"
}
}
}
}
}
'
curl -XGET 'localhost:9200/test/_mapping'
curl -XPUT 'localhost:9200/test/virksomhed/1' -d '
{
"Vrvirksomhed": {
"cvrNummer": 10237513,
"dataAdgang": 0,
"enhedsNummer": 4000800895,
"enhedstype": "VIRKSOMHED",
"fejlRegistreret": false,
"fejlVedIndlaesning": false,
"harFremtidigAendring": false,
"livsforloeb": [
{
"gyldigFra": "1972-12-19",
"gyldigTil": "2002-12-18",
"sidstOpdateret": "1999-10-16T19:49:47.000+02:00"
}
],
"samtId": 2,
"sidstIndlaest": "2015-01-05T14:44:58.582+01:00",
"sidstOpdateret": "2014-11-03T00:00:00.000+01:00",
"virksomhedsstatus": [
{
"gyldigFra": "1972-12-19",
"gyldigTil": "1991-11-07",
"sidstOpdateret": "2014-09-24T00:00:00.000+02:00",
"status": "NORMAL"
},
{
"gyldigFra": "2011-08-19",
"gyldigTil": "2011-09-01",
"sidstOpdateret": "2014-09-24T00:00:00.000+02:00",
"status": "NORMAL"
}
]
}
}
'
curl -XGET 'localhost:9200/test/_refresh'
curl -XGET 'localhost:9200/test/_search?pretty' -d '
{
"query": {
"nested": {
"path": "Vrvirksomhed.virksomhedsstatus",
"query": {
"bool": {
"must": [
{
"range": {
"Vrvirksomhed.virksomhedsstatus.gyldigFra": {
"lt": "2011-08-20"
}
}
},
{
"range": {
"Vrvirksomhed.virksomhedsstatus.gyldigTil": {
"gt": "2011-08-20"
}
}
}
]
}
}
}
}
}
'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment