1

I've been trying to search my ES database using the "term" query. I keep getting 0 hits.

Here's my mapping:

function initUserMapping() {
return elasticClient.indices.putMapping({
    index: "user",
    type: "document",
    body: {
        properties: {
            fullName: { type: "string", index: "not_analyzed" },
            email: { type: "string", index: "not_analyzed" },
            password: { type: "string", index: "not_analyzed" },
            movies: { type: "object" }
            }
        }
    }); 
}

This is how I am adding values to the "user" index (all the values are of type string except for movies):

function addUser(User) {
console.log(User);
return elasticClient.index({
    refresh: true,
    index: "user",
    type: "document",
    body: {
        properties: {
            fullName: User.fullName,
            email: User.email,
            password: User.password,
            movies: {}
        }
    }
});
}

This is one of the many permutations I have tried to query the db:

function loginUser(User) {
console.log(User);
return elasticClient.search({
    index: 'user',
    body: {
        query: {
            term: {
                email: User.email
            }
        }
    }
});
}

And this is the response I consistently get:

{
"took": 0,
"timed_out": false,
"_shards": {
    "total": 5,
    "successful": 5,
    "skipped": 0,
    "failed": 0
},
"hits": {
    "total": 0,
    "max_score": null,
    "hits": []
}
}
Joel Menezes
  • 27
  • 1
  • 5

0 Answers0