【发布时间】:2016-03-29 13:22:18
【问题描述】:
我正在使用 ElasticSearch 1.4.2,我想对某些字段和索引执行 Term 查询。因此,我设法使用以下
curl -XPUT localhost:9200/_river/modelsymptom/_meta -d '{
"type": "mongodb",
"mongodb": {
"servers": [
{ "host": "localhost", "port": 27017 }
],
"db": "bosch",
"collection": "Model_Symptom",
"options": { "secondary_read_preference": true },
"gridfs": false
},
"index": {
"name": "modelsymptom",
"type": "diagnosis",
"analyzer": "not_analyzed",
"mappings": {
"modelsymptom": {
"properties": {
"symptom_id": {
"type": "string",
"analyzer": "not_analyzed"
},
"probability": {
"type": "string"
},
"casue_id": {
"type": "string"
},
"doc_type": {
"type": "string",
"index": "not_analyzed"
},
"model_id": {
"type": "string",
"index": "not_analyzed"
}
}
}
}
}
}'
但它不起作用,术语查询仍然不返回任何数据,当我查看索引元数据时,我看到分析器部分听起来没有应用,而且概率字段的类型为 Long 虽然我设置它为字符串
{
"state": "open",
"settings": {
"index": {
"creation_date": "1459257376193",
"number_of_shards": "5",
"number_of_replicas": "0",
"version": {
"created": "1040299"
},
"uuid": "3srr-KU8TYq8_kYPPaIVZg"
}
},
"mappings": {
"diagnosis": {
"properties": {
"symptom_id": {
"type": "string"
},
"probability": {
"type": "long"
},
"casue_id": {
"type": "string"
},
"doc_type": {
"type": "string"
},
"model_id": {
"type": "string"
}
}
}
},
"aliases": []
}
从 JAVA API 到不检索任何结果的术语查询的代码示例:
client.prepareSearch(IndexNames.Model_Symptom_ErrorCodeIndex)
.setQuery(QueryBuilders.boolQuery().must(QueryBuilders.termQuery("symptom_id", SymptomID))
.must(QueryBuilders.termQuery("model_id", ModelID)))
我做错了什么?
【问题讨论】:
-
您能否附加索引和搜索查询中的示例文档
-
是的,如果您提及您正在运行的查询会很有帮助
-
我添加了一个代码 sn-p 用于我在应用程序中使用的内容
标签: java elasticsearch