[英]exact match query in elasticsearch
我正在尝试在ES中运行完全匹配查询
在MYSQL我的查询将是:
SELECT * WHERE `content_state`='active' AND `author`='bob' AND `title` != 'Beer';
我在这里查看了ES文档:
https://www.elastic.co/guide/zh-CN/elasticsearch/guide/current/_finding_exact_values.html
并提出了这个:
{
"from" : '.$offset.', "size" : '.$limit.',
"filter": {
"and": [
{
"and": [
{
"term": {
"content_state": "active"
}
},
{
"term": {
"author": "bob"
}
},
{
"not": {
"filter": {
"term": {
"title": "Beer"
}
}
}
}
]
}
]
}
}
但我的搜索结果仍然以标题= Beer为准,似乎并没有排除= Beer的标题。
我做错什么了吗?
我对ES很陌生
我想通了,我改用这个...
{
"from" : '.$offset.', "size" : '.$limit.',
"query": {
"bool": {
"must": [
{
"query_string": {
"default_field": "content_state",
"query": "active"
}
},
{
"query_string": {
"default_field": "author",
"query": "bob"
}
}
],
"must_not": [
{
"query_string": {
"default_field": "title",
"query": "Beer"
}
}
]
}
}
}
过滤器应该在精确值上工作 ,如果您以title是未分析字段的方式定义了映射,则先前的尝试(使用过滤器)也可以工作。
{
"mappings": {
"test": {
"_all": {
"enabled": false
},
"properties": {
"content_state": {
"type": "string"
},
"author": {
"type": "string"
},
"title": {
"type": "string",
"index": "not_analyzed"
}
}
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.