Hi all,
I'm coming across some odd behavior and wondering if I'm missing something
or if it's a bug.
I created an index (see script below), and added some documents. There is
a mapping for a multi_field type, and objects of type java.util.List are
used as values. When I pull back a single document using curl, the json
looks like I would expect. However, when I do a simple bool query using
the Java api against the same index, the multi_field property is nested
inside an extra ArrayList. This ArrayList has a single entry, which is the
list I expect. Where did the extra wrapping collection come from? I know
it has to do with using the multi_field type, because when I map the
property directly to a string type it works as I would expect. And the
returned json doesn't change when I use curl...
Please let me know if any of the above needs clarification... not as easy
to copy and paste in java objects as it is json.
Thanks in advance for any insights.
Matt
Index creation script:
curl -XPUT http://server:9200/photoindex1/ -d @photoIndex1.json
photoIndex1.json (abbreviated):
{
"settings" : {
"analysis" : {
"analyzer" : {
"stemmingloweringanalyzer" : {
"type" : "custom",
"tokenizer" : "lowercase",
"filter" : ["porterStem"]
}
}
}
},
"mappings" : {
"photoType" : {
"_source" : {
"enabled" : true
},
"_all" : {
"analyzer" : "default",
"enabled" : true
},
"properties" : {
"photoId" : {
"type" : "integer",
"store" : "yes",
"index" : "no",
"include_in_all" : false
},
"tags" : {
"type" : "multi_field",
"fields" : {
"tags" : {
"type" : "string",
"index_name" : "tag",
"store" : "no",
"index" : "analyzed",
"analyzer" : "stemmingloweringanalyzer",
"include_in_all" : true,
"boost" : 0.7
},
"untouched" : {
"type" : "string",
"index_name" : "tag",
"store" : "yes",
"index" : "not_analyzed"
}
}
}
}
}
}
}
Get a document using curl (doesn't change if I reindex without the
multi_field type and instead have a mapping to string type):
curl -XGET http://dsearchin001:9200/photoalias/photoType/40
{
"_index":"photoindex1",
"_type":"photoType",
"_id":"40",
"_version":1,
"exists":true,
"_source" : {
"tags": ["white kitchen cabinets","light brown granite counter
tops","recessed can lights","stainless steel refrigerator","bright"],
"photoId":40
}
}
Java code that I would expect to work....
protected List extractListField(String fieldName, SearchHit hit,
Class genericClass)
{
Map<String, SearchHitField> fieldMap = hit.getFields();
SearchHitField hitField = fieldMap.get(fieldName);
List list = Lists.newLinkedList();
if (hitField != null && hitField.getValues() != null &&
!hitField.getValues().isEmpty())
{
Collection values = (Collection) hitField.getValues();
list.addAll(values);
}
return list;
}
Java code I actually have to use...
protected List extractListField(String fieldName, SearchHit hit,
Class genericClass)
{
Map<String, SearchHitField> fieldMap = hit.getFields();
SearchHitField hitField = fieldMap.get(fieldName);
List list = Lists.newLinkedList();
if (hitField != null && hitField.getValues() != null &&
!hitField.getValues().isEmpty())
{
// Note the use of getValue() instead of getValues()
Collection values = (Collection) hitField.getValue();
list.addAll(values);
}
return list;
}
--