0

Something very very strange is happening with ES JS Client. client.search() method seems to work properly, index and search data work correctly, but if a restart the elasticsearch.bat then the client stops working. I mean, client.search gives me 0 hits with same code. But if I search using any rest client, I find all documents availables in the index.

This is the mapping using this GET http://localhost:9200/yojuego/_mappings:

{
    "yojuego": {
        "mappings": {
            "user": {
            "properties": {
                "password": {
                    "type": "string"
                    }
                "type": {
                    "type": "string"
                     }
                "userid": {
                    "type": "string"
                    }
                }
            }
        }
    }
}

Here is how I'm looking for the information from NodeJS:

this.client.search({
    index: "yojuego",
    type: "user",
    body: {
        "query": {
            "filtered": {
                "filter": {
                    "bool": {
                        "must": [
                            { "term": { "userid": criteria } },
                            { "term": { "type": "yojuego" } }
                        ]
                    }
                }
            }
        }
    }
}, (error, response, status) => {
    if (error) {
        //I have no error
    }
    else {
        //Here is where I have 0 hits in response.hits.hits
    }
});

Related post:

I've received many answers, all worked properly at first, but then all of them stopped working

Frameworks I'm using:

  • ElasticSearch 2.4.0
  • Node.js 6.3.0
  • ElasticSearch.js 11.0.1

How did I install ElasticSearch? Just downloading it from ES WebSite, unzipping it and running elasticsearch.bat (I'm running on Windows 7)

Again, the problem is that ES stops working after ES service is resetted. I'm pretty sure I'm doing something wrong, of course, but I can't realize where and what and why ES Service Search stop working sudeenly.

When i say "stop working" I'm saying that the search method from ES js client retrieve 0 matches with the same query as it was using yesterday.

I hope I explained it clearly. Thanks.

PD:

Here is how I'm initializating es client:

var es = require('elasticsearch');
var client = new es.Client({
    host: 'http://localhost:9200',
    log: 'info'
});
Community
  • 1
  • 1
Facundo La Rocca
  • 3,786
  • 2
  • 25
  • 47

1 Answers1

0

Well, after too much effort I've found that the problem is in the way I was mapping the userId field. I was forggeting to mark it as not_analized, so here is how it looks like:

{
    "yojuego": {
        "mappings": {
            "user": {
            "properties": {
                "password": {
                    "type": "string"
                    }
                "type": {
                    "type": "string",
                    "index": "not_analyzed"
                     }
                "userid": {
                    "type": "string",
                    "index": "not_analyzed"
                    }
                }
            }
        }
    }
}
Facundo La Rocca
  • 3,786
  • 2
  • 25
  • 47