我是弹性搜索新手,这是我在我的收藏中找到完全匹配的查询。
{
"query": {
"filtered": {
"query": {
"match": {
"_id": {
"query": "1"
}
}
},
"filter": {
"term" : {
"team_id":"2",
"created_user":"099"
}
}
}
}
}
通过运行此查询,我得到一条记录,但我的问题是它不匹配" team_id"提起。当我将team_id更改为其他值时,例如:4,我仍然使用team_id = 2获取记录,请帮我编写一个包含三个字段的弹性搜索查询。谢谢
答案 0 :(得分:1)
如果您想要完全匹配,请确保您要进行搜索操作的字段必须为not_analyzed。而且您的过滤器中似乎使用了多个案例。您可以使用and filter之类的重构来重构您的查询;
{
"query": {
"filtered": {
"query": {
"match": {
"_id": {
"query": "1" // remember that, this will always return one result. Update here according to your needs. For example, use tag instead of _id like tag=responsive in order to get results that matches tag field with responsive
}
}
},
"filter": {
"and": [
{
"term": {"team_id":"2"}
},
{
"term": {"created_user":"099"}
}
]
}
}
}