1

could anyone help me? Im new in elasticSearch and node.js.

REQUEST

app.get('/', function (req, res, next){
try {
    client.search({
        index: 'dbcatalogo',
        type: 'cars',
        size: 10,
        body: {
            query: {
                function_score:{
                    functions:[{
                        random_score:{
                            seed: 1
                        }
                    }]
                },
                match_all: {}
            },
            sort: {
                'AnoModelo': 'desc'
            }
        }
    }).then(function (json) {               
        res.json(json.hits);
    }, 
    function (err) {res.json(error.HandleError(err));});
}
catch (err) { res.json(error.HandleError(err)); }});

RESPONSE

[parse_exception] failed to parse search source. expected field name but got [START_OBJECT]

1 Answer 1

0

You are almost there the match_all needs to be within the query object of function_score as shows in function score below .

Example:

client.search({
    index: 'dbcatalogo',
    type: 'cars',
    size: 10,
    body: {
        query: {
            function_score:{
                functions:[{
                    random_score:{
                        seed: 1
                    }
                }],
                query : {
                    match_all: {}
            }
        }
        },
        sort: {
            'AnoModelo': 'desc'
        }
    }
}).then(function (json) {
    res.json(json.hits);
}

Also if you are sorting on a field other than score the random_score does not make much sense.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.