Last active
          August 17, 2016 23:49 
        
      - 
      
- 
        Save spazm/efb652831e6fb0f9db4e6640a31e3817 to your computer and use it in GitHub Desktop. 
    elasticsearch: strings in integer field
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | curl -XPUT "https://localhost:9200/int_vs_str_test" -d '{"mappings": { "foo" : { "properties": { "label_id": { "type": "integer"}}}}}' | |
| {"acknowledged":true} | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | curl -XGET "https://127.0.0.1:9200/int_vs_str_test/_mapping/foo?pretty=1" | |
| { | |
| "int_vs_str_test" : { | |
| "mappings" : { | |
| "foo" : { | |
| "properties" : { | |
| "label_id" : { | |
| "type" : "integer" | |
| } | |
| } | |
| } | |
| } | |
| } | |
| } | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | curl -XPUT "https://localhost:9200/int_vs_str_test/foo/1" -d '{"label_id" : [1,"2",3]}' | |
| {"_index":"int_vs_str_test","_type":"foo","_id":"1","_version":1,"_shards":{"total":2,"successful":2,"failed":0},"created" | |
| :true} | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | curl -XGET "https://127.0.0.1:9200/int_vs_str_test/foo/1?pretty=1" | |
| { | |
| "_index" : "int_vs_str_test", | |
| "_type" : "foo", | |
| "_id" : "1", | |
| "_version" : 1, | |
| "found" : true, | |
| "_source" : { | |
| "label_id" : [ 1, "2", 3 ] | |
| } | |
| } | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | curl -XPUT "https://rdb.dev.ziprecruiter.com:9200/int_vs_str_test/foo/1?pretty=1" -d ' | |
| {"implicit_long" : [1,"2",3]}' | |
| { | |
| "error" : { | |
| "root_cause" : [ { | |
| "type" : "mapper_parsing_exception", | |
| "reason" : "failed to parse" | |
| } ], | |
| "type" : "mapper_parsing_exception", | |
| "reason" : "failed to parse", | |
| "caused_by" : { | |
| "type" : "illegal_argument_exception", | |
| "reason" : "mapper [implicit_long] of different type, current_type [long], merged_type [string]" | |
| } | |
| }, | |
| "status" : 400 | |
| } | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | curl -XPUT "https://localhost:9200/int_vs_str_test/_mapping/foo?pretty=1" -d ' | |
| {"properties": {"explicit_long": {"type": "long"}}}' | |
| { | |
| "acknowledged" : true | |
| } | |
| curl -XPUT "https://localhost:9200/int_vs_str_test/foo/1?pretty=1" -d '{"explicit_long" : [1,"2",3]}' | |
| { | |
| "_index" : "int_vs_str_test", | |
| "_type" : "foo", | |
| "_id" : "1", | |
| "_version" : 2, | |
| "_shards" : { | |
| "total" : 2, | |
| "successful" : 2, | |
| "failed" : 0 | |
| }, | |
| "created" : false | |
| } | |
| curl -XGET "https://rdb.dev.ziprecruiter.com:9200/int_vs_str_test/foo/1?pretty=1" | |
| { | |
| "_index" : "int_vs_str_test", | |
| "_type" : "foo", | |
| "_id" : "1", | |
| "_version" : 2, | |
| "found" : true, | |
| "_source" : { | |
| "explicit_long" : [ 1, "2", 3 ] | |
| } | |
| } | 
I run into an issue using groovy scripting and .contains()
ctx._source["label_ids"].contains(1) <== True
ctx._source["label_ids"].contains(2) <== False
ctx._source["label_ids"].contains("2") <== True
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment
  
            
Elasticsearch allows me to insert string values into integer fields. Why does this work? Can I make it store
"2"as2?