我有问题。在我的JSON请求中添加过滤器时,我的搜索结果返回零
{
"body":
{
"query":{
"multi_match":
{
"query":"Joe Jerick Aparments",
"fields":["name","Category","address","description"]}
},
"filter":
{
"source":"Category":"Apartments"
}
} }
首先,
谢谢!
答案 0 :(得分:1)
{
index: "stores",
type: "stores",
id: "1",
body: {
name: "Joe Jerick Apartments",
Category: "Apartments"
address: "Somewhere down the road",
description: "Best apartment yet!"
}
}
所以,我在之前的评论中没有看到这一点,但是如果您要查询的字段嵌套在正文中(在存储中 - 而不是在检索中),那么您需要一个{ {3}}以获取列出的字段(我不确定您是否正在描述您的映射或在查询检索中查找match_all的内容)
如果是这种情况,您需要将身体映射为"嵌套"然后你的查询看起来像这样。
{
"query": {
"filtered": {
"query": {
"multi_match": {
"query": "Joe Jerick Apartments",
"fields": [
"body.name",
"body.Category",
"body.address",
"body.description"
]
}
},
"filter": {
"term": {
"body.Category": "Apartments"
}
}
}
}
}
您可以使用扁平结构重新导入记录
{
"id": "1",
"name": "Joe Jerick Apartments",
"Category": "Apartments",
"address": "Somewhere down the road",
"description": "Best apartment yet!"
}
答案 1 :(得分:0)
请尝试此查询:
{
"query": {
"filtered": {
"query": {
"multi_match": {
"query": "Joe Jerick Apartments",
"fields": [
"name",
"Category",
"address",
"description"
]
}
},
"filter": {
"term": {
"Category": "Apartments"
}
}
}
}
}