2

I am trying to build an index in elasticsearch and search the numerical fields afterwards. The resultset is empty, even thouhg the logical result would be to have a 1 record resultset.

Below the actions to reproduce (using sense)

Create the index

PUT playground

Create a document

POST playground/doc
{
   "value": {
      "textlabel": "Lorem Ipsum",
      "numerlabel": 37.0,
      "datelabel":"1978-10-26T00:00:00+02:00"
   }
}

The autogenerated mapping file seems to provide the proper data types

{
   "playground": {
      "mappings": {
         "doc": {
            "properties": {
               "value": {
                  "properties": {
                     "datelabel": {
                        "type": "date",
                        "format": "dateOptionalTime"
                     },
                     "numerlabel": {
                        "type": "double"
                     },
                     "textlabel": {
                        "type": "string"
                     }
                  }
               }
            }
         }
      }
   }
}

Searching on date ranges works fine, returning the expected data

POST playground/doc/_search
{
    "query": {         
        "filtered": {           
           "filter": {
               "range" : {
                    "value.datelabel" : {                        
                        "lte": "now-28y" 
                    }
                }
           }
        }
    }
}

But numeric ranges do not return any results

POST playground/doc/_search
{
    "query": {
      "filtered": {           
           "filter": {
               "range":  {
                    "value.numberlabel" : {             
                        "lte": 100
                    }
                }
           }
        }
    }
}

results in

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

Any suggestions why?

2 Answers 2

2

You have a typo: numerlabel - numberlabel. The correct query, given that mapping is:

{
  "query": {
    "filtered": {
      "filter": {
        "range": {
          "value.numerlabel": {
            "lte": 100
          }
        }
      }
    }
  }
}
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you Andrei - I checked the spelling of the query 100 times... but did not look at the document creation. Thanks a lot!
2

You just had a misspelling. "numerlabel" in your document, but "value.numberlabel" in your query.

After I ran your set-up code, this works:

POST playground/doc/_search
{
    "query": {
      "filtered": {           
           "filter": {
               "range":  {
                    "value.numerlabel" : {             
                        "lte": 100
                    }
                }
           }
        }
    }
}
...
{
   "took": 3,
   "timed_out": false,
   "_shards": {
      "total": 5,
      "successful": 5,
      "failed": 0
   },
   "hits": {
      "total": 1,
      "max_score": 1,
      "hits": [
         {
            "_index": "playground",
            "_type": "doc",
            "_id": "AU5UiwngQAg_uFp56nys",
            "_score": 1,
            "_source": {
               "value": {
                  "textlabel": "Lorem Ipsum",
                  "numerlabel": 37,
                  "datelabel": "1978-10-26T00:00:00+02:00"
               }
            }
         }
      ]
   }
}

1 Comment

Thanks Sloan, I checked the spelling of the query 100 times... but did not look at the document creation. Thanks a lot! As Andrei was just a bit earlier, I'll accept his answers - yours being equally correct :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.