elasticsearch,lucene,Javascript,Json,elasticsearch,Lucene" /> elasticsearch,lucene,Javascript,Json,elasticsearch,Lucene" />

Javascript ElasticSearch错误:[term]查询不支持不同的字段名,请改用[bool]查询

Javascript ElasticSearch错误:[term]查询不支持不同的字段名,请改用[bool]查询,javascript,json,elasticsearch,lucene,Javascript,Json,elasticsearch,Lucene,我目前正在使用ElasticSearch v2.3.2,在调试查询错误时遇到问题。查询似乎工作正常,但仍会抛出错误: [query\u parsing\u exception][term]查询不支持不同的 字段名,请改用[bool]查询 我当前的ElasticSearch查询如下: var must = []; must.push({ not: { term: { 'zip': '00000' }}}); var request = { index: 'my-index',

我目前正在使用ElasticSearch v2.3.2,在调试查询错误时遇到问题。查询似乎工作正常,但仍会抛出错误:

[query\u parsing\u 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"
            }
        }]
    }
};
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”子句,如下所示:

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"
            }
        }]
    }
};
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”子句移动到过滤器数组中,现在会产生正确的搜索结果,但仍会抛出此错误。您知道如何清除此错误吗?

错误消息意味着您应该将组合术语筛选器扩展为包含两个子句的布尔筛选器:

"term" : { "listing.rentForSale" : "R" }

这两个句子被
not:{bool:{should:{[两个子句]}}}

这取决于你想要得到什么的确切含义,如果你使用了
必须
应该
(注意否定和评分)

希望有帮助,
fricke

正确的方法是使用
bool/must\u not

var request = {
    index: 'my-index',
    type: 'property',
    body: {
        from : page * perPage,
        size : perPage,
        query: {
            bool: {
                must_not: [
                    {
                        "term" : {
                                "listing.rentForSale" : "R"
                        }
                    },
                    {
                        "term" : {
                                "listing.statusCode" : "Rented"
                        }
                    },
                    {
                        "term" : {
                                "zip" : "00000"
                        }
                    }
                ],
                filter : [
                    {
                        geo_distance : {
                            distance : range + 'mi',
                            'position' : point
                        }    
                    }
                ]

            }
        },
        sort: [{
            _geo_distance: {
                "position": point,
                "order":         "asc",
                "unit":          "mi",
                "distance_type": "plane"
            }
        }]
    }
};

我最初在bool过滤器中有这两个term子句,但这并没有产生正确的搜索结果。我编辑了我的问题以反映这一点。将not:{bool:{shoul:{[两个子句]}}}替换为{bool:[{term:{'listing.rentForSale':“R”}},{not:{term:{'listing.statusCode':“Rented”}}}