Skip to content

Instantly share code, notes, and snippets.

@tstibbs
Last active August 29, 2015 14:03
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 tstibbs/dc36483f96f8d1471385 to your computer and use it in GitHub Desktop.
Save tstibbs/dc36483f96f8d1471385 to your computer and use it in GitHub Desktop.
Elasticsearch field 'copy_to' disagrees with itself
curl -XPUT 'http://localhost:9200/index1' -d '
{
"mappings": {
"parent": {
"properties": {
"children": {
"type": "nested",
"properties": {
"colour": {
"type": "string"
},
"make": {
"type": "string",
"copy_to": "copied"
}
}
}
}
}
}
}
'
curl -XPUT 'http://localhost:9200/index1/parent/1' -d '
{
"children": [
{
"colour": "blue",
"make": "ford"
},
{
"colour": "red",
"make": "rover"
}
]
}
'
curl -XGET 'http://localhost:9200/index1/_mapping?pretty=true'
# returns this (note the location of the 'copied' field):
{
"index1" : {
"mappings" : {
"parent" : {
"properties" : {
"children" : {
"type" : "nested",
"properties" : {
"colour" : {
"type" : "string"
},
"make" : {
"type" : "string",
"copy_to" : [ "copied" ]
}
}
},
"copied" : {
"type" : "string"
}
}
}
}
}
}
# From looking at the mapping, we would expect this query to return the document (it doesn't):
curl -XPOST 'http://localhost:9200/index1/_search' -d '
{
"query": {
"bool": {
"must": [
{
"match" : {
"copied" : "rover"
}
},
{
"nested": {
"path": "children",
"score_mode": "avg",
"query": {
"match": {
"colour": "red"
}
}
}
}
]
}
}
}
'
# From looking at the mapping, we would not expect this query to return the document (it does):
curl -XPOST 'http://localhost:9200/index1/_search' -d '
{
"query": {
"nested": {
"path": "children",
"score_mode": "avg",
"query": {
"bool": {
"must": [
{
"match": {
"copied": "rover"
}
},
{
"match": {
"colour": "red"
}
}
]
}
}
}
}
}
'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment