# Termquery is failing

**URL:** <https://discuss.elastic.co/t/termquery-is-failing/133174>\
**Category:** Elasticsearch\
**Created:** [May 24, 2018, 2:43pm UTC](https://discuss.elastic.co/t/termquery-is-failing/133174 "2018-05-24T14:43:42Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![kish](https://avatars.discourse-cdn.com/v4/letter/k/71e660/32.png) [@kish](https://discuss.elastic.co/u/kish)\
**Post date:** [May 24, 2018, 2:43pm UTC](https://discuss.elastic.co/t/termquery-is-failing/133174/1 "2018-05-24T14:43:42Z")

</div>

Hello -

I have the following query

> ```
> searchResult, err := elasticSearchClient.Search().
> Index("cscfcounter"). // search in index
> Query(elastic.NewTermQuery("NodeId", rn)). // specify the query
> Sort("date", false).
> Size(1).
> Pretty(true).
> Do(elasticSearchContext) // execute
> 
> ```

Here 'rn' -\> will be nodeid as swevmware-cscf02  
And i tried to print the results

```
2018/05/24 14:31:44 cscf node id swevmware-cscf04 swevmware-cscf04
2018/05/24 14:31:44 searchResult.Hits.TotalHits 0 &{1 0xc420780c30 map[] map[] false <nil> <nil> 0xc420610820}
2018/05/24 14:31:44 cscf node id swevmware-cscf01 swevmware-cscf01
2018/05/24 14:31:44 searchResult.Hits.TotalHits 0 &{1 0xc420698ab0 map[] map[] false <nil> <nil> 0xc4200c9ca0}
2018/05/24 14:31:44 cscf node id swevmware-cscf02 swevmware-cscf02
2018/05/24 14:31:44 searchResult.Hits.TotalHits 0 &{2 0xc420781290 map[] map[] false <nil> <nil> 0xc420610c00}
2018/05/24 14:31:44 cscf node id swevmware-cscf03 swevmware-cscf03
2018/05/24 14:31:44 searchResult.Hits.TotalHits 0 &{1 0xc4207817a0 map[] map[] false <nil> <nil> 0xc420611020}

```

But my searchResult.Hits.TotalHits is always 0. even though i have the data as below...

```
{
  "took" : 11,
  "timed_out" : false,
  "_shards" : {
    "total" : 5,
    "successful" : 5,
    "failed" : 0
  },
  "hits" : {
    "total" : 17326,
    "max_score" : null,
    "hits" : [
      {
        "_index" : "cscfcounter",
        "_type" : "cscfcounter",
        "_id" : "AWOMcdCZAVP1xFvMoV3N",
        "_score" : null,
        "_source" : {
          "CpuAverageLoad" : 0,
          "HaGroupId" : "100001",
          "LbGroupId" : "",
          "MemFree" : 100,
          "MemUsed" : 0,
          "NodeId" : "swevmware-cscf02",
          "NodeType" : "cscf",
          "QOverload" : 0,
          "State" : "online",
          "Static_limit" : 0,
          "date" : "2018-05-23T10:00:59.287797918Z"
        },
        "sort" : [
          1527069659287
        ]
      },
      {
        "_index" : "cscfcounter",
        "_type" : "cscfcounter",
        "_id" : "AWOMccToVBgXfszoulaR",
        "_score" : null,
        "_source" : {
          "CpuAverageLoad" : 0,
          "HaGroupId" : "100001",
          "LbGroupId" : "",
          "MemFree" : 100,
          "MemUsed" : 0,
          "NodeId" : "swevmware-cscf01",
          "NodeType" : "cscf",
          "State" : "online",
          "Static_limit" : 0,
          "date" : "2018-05-23T10:00:56.294530047Z"
        },
        "sort" : [
          1527069656294
        ]
      },
      {
        "_index" : "cscfcounter",
        "_type" : "cscfcounter",
        "_id" : "AWOMcOXYAVP1xFvMoV3K",
        "_score" : null,
        "_source" : {
          "CpuAverageLoad" : 0,
          "HaGroupId" : "100001",
          "LbGroupId" : "",
          "MemFree" : 100,
          "MemUsed" : 0,
          "NodeId" : "swevmware-cscf02",
          "NodeType" : "cscf",
          "QOverload" : 0,
          "State" : "online",
          "Static_limit" : 0,
          "date" : "2018-05-23T09:59:59.190944802Z"
        },
        "sort" : [
          1527069599190
        ]
      },
      {
        "_index" : "cscfcounter",
        "_type" : "cscfcounter",
        "_id" : "AWOMb-_KVBgXfszoulaN",
        "_score" : null,
        "_source" : {
          "CpuAverageLoad" : 0,
          "HaGroupId" : "100001",
          "LbGroupId" : "",
          "MemFree" : 100,
          "MemUsed" : 0,
          "NodeId" : "swevmware-cscf01",
          "NodeType" : "cscf",
          "State" : "online",
          "Static_limit" : 0,
          "date" : "2018-05-23T09:58:56.201215006Z"
        },
        "sort" : [
          1527069536201
        ]
      },
      {
        "_index" : "cscfcounter",
        "_type" : "cscfcounter",
        "_id" : "AWOMbxG6AVP1xFvMoV3C",
        "_score" : null,
        "_source" : {
          "CpuAverageLoad" : 0,
          "HaGroupId" : "100001",
          "LbGroupId" : "",
          "MemFree" : 100,
          "MemUsed" : 0,
          "NodeId" : "swevmware-cscf02",
          "NodeType" : "cscf",
          "QOverload" : 0,
          "State" : "online",
          "Static_limit" : 0,
          "date" : "2018-05-23T09:57:59.352869379Z"
        },
        "sort" : [
          1527069479352
        ]
      }
    ]
  }
}

```

---

<div class="post-metadata">

**Author:** ![Ivan](https://avatars.discourse-cdn.com/v4/letter/i/df788c/32.png) [@Ivan](https://discuss.elastic.co/u/Ivan)\
**Post date:** [May 24, 2018, 3:25pm UTC](https://discuss.elastic.co/t/termquery-is-failing/133174/2 "2018-05-24T15:25:03Z")

</div>

What is the mapping for field NodeId in index cscfcounter? The default for string fields is text (analyzed), which means they will not work well with term queries (non-analyzed).

---

<div class="post-metadata">

**Author:** ![kish](https://avatars.discourse-cdn.com/v4/letter/k/71e660/32.png) [@kish](https://discuss.elastic.co/u/kish)\
**Post date:** [May 24, 2018, 3:27pm UTC](https://discuss.elastic.co/t/termquery-is-failing/133174/3 "2018-05-24T15:27:18Z")

</div>

Hi,  
The mapping is as follow

> ```
> const cscfMappaing = `
> {
> "settings": {
> },
> "mapping": {
> "cscfcounter":{
> "properties":{
> "date": {
> "type": "date"
> },
> "NodeId":{
> "type":"keyword"
> },
> "NodeType":{
> "type":"keyword"
> },
> "State":{
> "type":"keyword"
> },
> "HaGroupId":{
> "type":"keyword"
> },
> "LbGroupId":{
> "type":"keyword"
> },
> "CpuAverageLoad":{
> "type":"keyword"
> },
> "MemUsed":{
> "type":"keyword"
> },
> "MemFree":{
> "type":"keyword"
> },
> "Static_limit":{
> "type":"keyword"
> }
> }
> }
> 		
> }
> 	
> }`
> 
> ```

---

<div class="post-metadata">

**Author:** ![kish](https://avatars.discourse-cdn.com/v4/letter/k/71e660/32.png) [@kish](https://discuss.elastic.co/u/kish)\
**Post date:** [May 24, 2018, 3:41pm UTC](https://discuss.elastic.co/t/termquery-is-failing/133174/4 "2018-05-24T15:41:24Z")

</div>

Hi,  
Actually it is working on server/node but not one particular setup. Is there any way to find any issue in ES. Even when i execute a operation on the node related ES no logs are getting collected in /elasticsearch/logs floder.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [June 21, 2018, 3:41pm UTC](https://discuss.elastic.co/t/termquery-is-failing/133174/5 "2018-06-21T15:41:27Z")

</div>

Closed on June 21, 2018, 3:41pm UTC

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
