【发布时间】:2015-11-19 13:27:39
【问题描述】:
我想执行全文搜索,但我也想使用一个或多个可能的过滤器。我的文档的简化结构,用/things/_search?q=*foo*搜索时:
{
"took": 5,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"failed": 0
},
"hits": {
"total": 1,
"max_score": 1,
"hits": [
{
"_index": "things",
"_type": "thing",
"_id": "63",
"_score": 1,
"fields": {
"name": [
"foo bar"
],
"description": [
"this is my description"
],
"type": [
"inanimate"
]
}
}
]
}
}
这很好用,但是如何将过滤器与查询结合起来?假设我想在包含多个文档的索引中搜索“foo”,但我只想获取 type == "inanimate" 的那些?
这是我目前的尝试:
{
"query": {
"filtered": {
"query": {
"query_string": {
"query": "*foo*"
}
},
"filter": {
"bool": {
"must": {
"term": { "type": "inanimate" }
}
}
}
}
}
}
当我删除 filter 部分时,它会返回一组准确的文档命中。但是使用此过滤器定义它不会返回任何内容,即使我可以手动验证是否存在带有type == "inanimate" 的文档。
【问题讨论】:
-
你把
type和_type搞混了吗?? -
你如何索引你的数据?
-
我不确定你的意思,但我使用 logstash-input-jdbc 来索引 MySQL 数据库中的数据?
-
你能把
curl -XGET 'http://localhost:9200/your_index/_mapping/your_type的输出贴出来 -
很明显这个例子被模拟为不显示真实数据。但是字段“type”是类型(heh)“string”。我没有做过任何“显式映射”。
标签: elasticsearch