Hi,
I am trying to hide nested fields per default and only showing them if
the 'fields' parameter is used in the query - which does not work as I
thought it would.
First my setup, a standard mapping
{
"test": {
"properties": {
"name": { "type": "string", "index":
"not_analyzed", "store" : "yes" },
"customPrices": { "store" : "yes", "type" : "object" }
},
"_source" : {
"excludes" : [ "customPrices", "name" ]
}
}
}
The mapping should define, that anything gets included, except name
(for testing purposes), which is a flat field and customPrices which
is a nested object
Now I index some object matching the above criteria
curl -X PUT localhost:9200/test/test/1 -d '{ "name" : "somename" ,
"foo" :"foo", "bar":"bar", "customPrices" : [ { "name" : "customer1",
"price" : 22.0}, { "name" : "customer2", "price" : 1000 } ] }'
Match all querying works
curl -X POST localhost:9200/test/test/_search?pretty=1 -d '{ "query" :
{ "match_all" : {}}}'
Returns the source like this: "_source" : {"foo":"foo","bar":"bar"}
curl -X POST localhost:9200/test/test/_search?pretty=1 -d '{ "query" :
{ "match_all" : {} }, "fields" : [ "name" ]}'
Does not return the source, but the fields array including the name field
However if I do a similar search for the customer, I fail and do not
get any fields, if I use one of these searches
curl -X POST localhost:9200/test/test/_search?pretty=1 -d '{ "query" :
{ "match_all" : {} }, "fields" : [ "customPrice" ]}'
curl -X POST localhost:9200/test/test/_search?pretty=1 -d '{ "query" :
{ "match_all" : {} }, "fields" : [ "customPrice.customer1" ]}'
curl -X POST localhost:9200/test/test/_search?pretty=1 -d '{ "query" :
{ "match_all" : {} }, "fields" : [ "*" ]}'
The last query does include the name field but not the customPrices one...
I am sure this is possible, but I am missing something or have a wrong
mapping configuration
Any hints greatly appreciated!
--Alexander
--