0

I have a number field on my index which works as a count and the problem is when I try to query that field equals 0, I don't get any value.

I'm sure about possible values in the Index because If I execute the query without any filter it returns at least 50 occurrences where the field equals 0.

I tried with term:

GET contacts/_search
  {
    "query": { 
      "term": {
        "investmentsCount": {
          "value": 0
        }
      }
    }
  }

or using range

GET contacts/_search
  {
    "query": { 
      "range": {
        "investmentsCount": {
          "lte": 0
        }
      }
    }
  }

Also, I tried with range with "lt": 1 and it didn't return anything. Even if I try less_than < 2, I receive just the ones with count = 1 but not the 0 ones. Any tips?

Sample Document:


GET contacts/_search
  {
    "query": { 
      "term": {
        "investmentsCount": {
          "value": 1
        }
      }
    }
  }

  "hits" : {
    "total" : {
      "value" : 432,
      "relation" : "eq"
    },
    "max_score" : 1.0,
    "hits" : [
      {
        "_index" : "contacts",
        "_type" : "_doc",
        "_id" : "1",
        "_score" : 1.0,
        "_source" : {
          "id" : "1",
          "accountId" : "1",
          "committed" : 7500000,          
          "contributed" : 7500000,
          "investedMax" : "2020-03-18T01:53:31.160Z",
          "investedMin" : "2020-03-18T01:53:31.160Z",
          "investmentsCount" : 1,
          "status" : "ACTIVE",
          "updated" : "2020-03-18T01:43:39.854Z",
          "userId" : "1",
          "withdrawnMax" : "2020-03-18T01:53:58.092Z",
          "withdrawnMin" : "2020-03-18T01:53:58.092Z"
        }
      }
    ]
  }
4
  • 1
    Can you add a sample document, could be issue of spelling of fieldname Commented Apr 24, 2020 at 14:45
  • I included in the answer, a result when I query by 1 investmentsCount Commented Apr 24, 2020 at 15:04
  • There is specifically 0 value or null? Commented Apr 24, 2020 at 15:05
  • No, when I query without a filter I saw them just as "investmentsCount" : 0 Commented Apr 24, 2020 at 15:09

1 Answer 1

1

Try to run a aggregate query to see the unique values of investmentsCount. In most probability, I am guessing that field is not being populated with value 0, in which case, you will need to correct your ingestion process.

Sign up to request clarification or add additional context in comments.

2 Comments

I think you are right, it didn't return the key = 0 in the aggregation response
Great. So correct your ingestion process and you should all set. Pls dont forget to mark the answer :)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.