我在mongo下的数据库中有3个集合:显示 - 场地 - 下拉列表
节目映射如下
public class CodesArrayAdapter extends ArrayAdapter implements Filterable{
List<String> allCodes;
List<String> originalCodes;
StringFilter filter;
public CodesArrayAdapter(Context context, int resource, List<String> keys) {
super(context, resource, keys);
allCodes=keys;
originalCodes=keys;
}
public int getCount() {
return allCodes.size();
}
public Object getItem(int position) {
return allCodes.get(position);
}
public long getItemId(int position) {
return position;
}
private class StringFilter extends Filter {
@Override
protected FilterResults performFiltering(CharSequence constraint) {
String filterString = constraint.toString().toLowerCase();
FilterResults results = new FilterResults();
final List<String> list = originalCodes;
int count = list.size();
final ArrayList<String> nlist = new ArrayList<String>(count);
String filterableString ;
for (int i = 0; i < count; i++) {
filterableString = list.get(i);
if (filterableString.toLowerCase().contains(filterString)) {
nlist.add(filterableString);
}
}
results.values = nlist;
results.count = nlist.size();
return results;
}
@SuppressWarnings("unchecked")
@Override
protected void publishResults(CharSequence constraint, FilterResults results) {
allCodes = (ArrayList<String>) results.values;
notifyDataSetChanged();
}
}
@Override
public Filter getFilter()
{
return new StringFilter();
}
}
像这样的场地
"show": {
"properties" : {
"description": {
"type": "string"
},
"image": {
"type": "string"
},
"site": {
"type": "string"
},
"title" : {
"type" : "multi_field",
"fields" : {
"title" : {"type" : "string", "index" : "analyzed"},
"raw_title" : {"type" : "string", "index" : "not_analyzed", "store": "no"}
}
}
}
}
我在mongo中使用此模型进行下拉:
"venues": {
"properties" : {
"name" : {
"type" : "multi_field",
"fields" : {
"name" : {"type" : "string", "index" : "analyzed"},
"raw_name" : {"type" : "string", "index" : "not_analyzed", "store": "no"}
}
},
"city" : {
"type" : "multi_field",
"fields" : {
"city" : {"type" : "string", "index" : "analyzed"},
"raw_city" : {"type" : "string", "index" : "not_analyzed", "store": "no"}
}
},
"region" : {
"type" : "multi_field",
"fields" : {
"region" : {"type" : "string", "index" : "analyzed"},
"raw_region" : {"type" : "string", "index" : "not_analyzed", "store": "no"}
}
},
"state" : {
"type": "boolean"
}
}
}
我将带有父/子模式的下拉列表映射到我的索引中,但是我无法理解是否可以使用ObjectId,因为我尝试过这种映射:
{
created: {
type: Date,
default: Date.now
},
analytics: {
type: String,
default: '',
trim: true
},
state: {
type: Boolean,
default: false,
index: true
},
show: {
type: Schema.ObjectId,
ref: 'Show'
},
venues:[{
venue:{
type: Schema.ObjectId,
ref: 'Venue',
index: true
},
site: {
type: String,
trim: true,
index: true
}
}]
}
但我收到了这个错误:
MapperParsingException [没有为属性[show]]指定类型
无论如何都要正确设置我的索引?
答案 0 :(得分:1)
问题是您未正确指定_parent
。您必须在properties
字段中设置它,而不是在它旁边。请参阅documentation及其中的示例:
PUT /company
{
"mappings": {
"branch": {},
"employee": {
"_parent": {
"type": "branch"
}
}
}
}
所以遵循这个逻辑,我已经采用了你的映射,简化了一点并使其工作:
PUT /test
{
"mappings": {
"show": {
"properties": {
"description": {
"type": "string"
},
"image": {
"type": "string"
},
"site": {
"type": "string"
},
"title": {
"type": "multi_field",
"fields": {
"title": {
"type": "string",
"index": "analyzed"
},
"raw_title": {
"type": "string",
"index": "not_analyzed",
"store": "no"
}
}
}
}
},
"venues": {
"properties": {
"name": {
"type": "multi_field",
"fields": {
"name": {
"type": "string",
"index": "analyzed"
},
"raw_name": {
"type": "string",
"index": "not_analyzed",
"store": "no"
}
}
},
"city": {
"type": "multi_field",
"fields": {
"city": {
"type": "string",
"index": "analyzed"
},
"raw_city": {
"type": "string",
"index": "not_analyzed",
"store": "no"
}
}
},
"region": {
"type": "multi_field",
"fields": {
"region": {
"type": "string",
"index": "analyzed"
},
"raw_region": {
"type": "string",
"index": "not_analyzed",
"store": "no"
}
}
},
"state": {
"type": "boolean"
}
}
},
"dropdown": {
"_parent": {
"type": "show"
},
"properties": {
"state": {
"type": "boolean"
},
"analytics": {
"type": "string"
},
"venues": {
"type": "object",
"_parent": {
"type": "venues"
},
"site": {
"type": "string"
}
}
}
}
}
}
我自己在Elasticsearch 1.7.1上尝试了这个,它运行良好。
但是,我不确定您是否可以像在场地中那样在嵌套文档中声明_parent
关系。我的映射查询没有抛出错误并接受它。然而,看看它是如何在头部插件中解析的 - _parent
被消除了,只剩下object
部分,如截图所示:
如果我尝试在不指定类型的情况下对其进行索引 - 则抛出此错误:
&#34; MapperParsingException [mapping [dropdown]];嵌套: MapperParsingException [没有为property [venues]指定类型];