Question: I have the following code

```js
var app = require('express')();
var http = require('http');
var server = http.createServer();
var socket = require('socket.io');
var io = socket.listen( server );

io.sockets.on('connection', function(socket) {
  console.log('socket connected');
  socket.broadcast.emit('newUser', 'New User Joined, Say Hi :D');

  socket.on('serverEmit',function(msg) {
    console.log('works');
  });

  socket.on('chatMessage', function(msg) {
    io.emit('server_emit', msg);
    console.log(msg);
  });
});

server.listen(3500, function() {
  console.log('listening on *:3500');
});

```

So my question is how to add an emit function outside of this socket connection. For example, if I have a get request like below

```js
app.get('/link',function(req,res) {
  io.sockets.emit('trigger','triggered'); // Process I want to make
});

```

Thanks in advance.

Answer: 
You can query with size `0`. `total` value will give you an idea that doc exists or not.

```
GET /twitter/user/_search
{"size": 0,
  "query": {"match": {
  "username": "xyz"
}}}

```

Edited -- 

`_count api can be used as well.`

```
GET /twitter/user/_count
{ "query": {"match": {
  "username": "xyz"
}}}

```
You can use term query with size 0. See below query for reference:

```
POST twitter/user/_search
{
    "query": {
        "term": {
           "username": "xyz"
        }
    },
    "size" : 0
}

```

Response:

```
{
"took": 1,
"timed_out": false,
"_shards": {
  "total": 5,
  "successful": 5,
  "failed": 0
},
"hits": {
  "total": 1,
  "max_score": 0,
  "hits": []
}
}

```

You will get total document count in **hits.total** and then you can check for *count > 0*