【发布时间】:2018-08-08 17:06:02
【问题描述】:
我目前正在使用 ElasticSearch v2.3.2,但在调试查询中的错误时遇到问题。查询似乎工作正常,但仍然抛出错误:
[query_parsing_exception] [term] 查询不支持不同 字段名称,请改用 [bool] 查询
我目前的 ElasticSearch 查询如下:
var must = [];
must.push({ not: { term: { 'zip': '00000' }}});
var request = {
index: 'my-index',
type: 'property',
body: {
from : page * perPage,
size : perPage,
query: {
bool: {
must,
filter : [
{
geo_distance : {
distance : range + 'mi',
'position' : point
}
},
{
"not" : {
"term" : {
"listing.rentForSale" : "R",
"listing.statusCode" : "Rented"
}
}
}
]
}
},
sort: [{
_geo_distance: {
"position": point,
"order": "asc",
"unit": "mi",
"distance_type": "plane"
}
}]
}
};
我的初始查询在 must 数组 中有 "not" 子句,如下所示:
var must = [];
must.push({ not: { term: { 'zip': '00000' }}});
must.push({ not: { term: { "listing.rentForSale" : "R" }}});
must.push({ not: { term: { "listing.statusCode" : "Rented" }}});
var request = {
index: 'my-index',
type: 'property',
body: {
from : page * perPage,
size : perPage,
query: {
bool: {
must,
filter : [
{
geo_distance : {
distance : range + 'mi',
'position' : point
}
}
]
}
},
sort: [{
_geo_distance: {
"position": point,
"order": "asc",
"unit": "mi",
"distance_type": "plane"
}
}]
}
};
这没有产生正确的结果。将 "not" 子句 移动到 filter 数组 现在会产生正确的搜索结果,但仍会引发此错误。有什么想法可以清除此错误吗?
【问题讨论】:
标签: javascript json elasticsearch lucene