如何在弹性搜索5.1中使用地理查询实现随机查询

时间:2018-02-20 17:57:32

标签: elasticsearch

var searchParams = {
        index: 'offers',
        body: {
            query: {
                function_score: {
                    query: {match_all: {}},
                    boost: '5',
                    functions: [
                        {
                            filter: {
                                geo_distance: {
                                    distance: radius,
                                    location: {
                                        lat: latitude,
                                        lon: longitude
                                    }
                                }
                            },
                            random_score: {},
                            weight: 23
                        }
                    ],
                    max_boost: 23,
                    score_mode: 'max',
                    boost_mode: 'multiply',
                    min_score: 23
                }
            }
        },
        filter_path: 'hits.hits._source',
        from: from,
        size: size,
        sort: ["_score"],
        pretty: 'true'

    };

这给我错误:

  

{错误:[parsing_exception] START_OBJECT中的未知密钥   [function_score]。,{line = 1& col = 19}回应   (/user_code/node_modules/elasticsearch/src/lib/transport.js:30:15)at at   checkRespForFailure   (/user_code/node_modules/elasticsearch/src/lib/transport.js:266:7)at at   HttpConnector。   (/user_code/node_modules/elasticsearch/src/lib/connectors/http.js:159:7)   在IncomingMessage.bound   (/user_code/node_modules/elasticsearch/node_modules/lodash/dist/lodash.js:729:21)   在IncomingMessage.emit的emitNone(events.js:91:20)   (events.js:185:7)at endReadableNT(_stream_readable.js:974:12)at at   _combinedTickCallback(internal / process / next_tick.js:80:11)at process._tickDomainCallback(internal / process / next_tick.js:128:9)   状态:400,displayName:' BadRequest',消息:' [parsing_exception]   [function_score]中START_OBJECT的未知键,{line = 1&   col = 19}',路径:' / offers / _search',查询:{filter_path:   ' hits.hits._source',from:0,size:2,sort:' _score',pretty:' true'   },body:{error:{root_cause:[Object],输入:' parsing_exception',   原因:' [function_score]中START_OBJECT的未知密钥。',行:   1,col:19},状态:400},statusCode:400,响应:' {\ n"错误" :   {\ n" root_cause" :[\ n {\ n" type" :" parsing_exception",\ n" reason" :   " [function_score]中START_OBJECT的未知键。",\ n" line" :1,\ n   " COL" :19 \ n} \ n],\ n"输入" :" parsing_exception",\ n" reason" :   " [function_score]中START_OBJECT的未知键。",\ n" line" :1,\ n   " COL" :19 \ n},\ n" status" :400 \ n} \ n',toString:[Function],toJSON:   [功能]}

如何解决?

node.js中是否有弹性搜索的包装器?

1 个答案:

答案 0 :(得分:-1)

搜索此软件包:将“ elasticsearch”转换为npm