the doc[...] notation only allows for simple valued fields (you can’t return a json object from it) and makes sense only for non-analyzed or single term based fields
However, depending on what you want to achieve here are some approaches:
DELETE test
PUT test
{
"settings": {
"number_of_replicas": 0,
"number_of_shards": 1
},
"mappings": {
"doc": {
"properties": {
"text": {
"type": "text",
"fielddata": true
}
}
}
}
}
POST test/doc
{
"text":"The quick brown fox"
}
//This returns only "brown"
GET test/_search
{
"query": {
"match_all": {}
},
"script_fields": {
"text": {
"script": {
"lang": "painless",
"source": "return doc['text'].value"
}
}
}
}
//This returns values (in this order): "brown", "fox", "quick", "the"
GET test/_search
{
"query": {
"match_all": {}
},
"script_fields": {
"text": {
"script": {
"lang": "painless",
"source": "return doc['text'].values"
}
}
}
}
//This returns value "The quick brown fox"
GET test/_search
{
"query": {
"match_all": {}
},
"_source": [
"text"
]
}
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.