Termquery is failing


(kish) #1

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
        ]
      }
    ]
  }
}

(Ivan Brusic) #2

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).


(kish) #3

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"
				}
			}
		}
		
	}
	
}`

(kish) #4

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.


(system) #5

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