按文字搜索字段

时间:2017-08-06 14:47:09

标签: elasticsearch

这是我的索引:

setTimeout

这是默认映射:

λ curl -XGET -u elastic:elasticpassword http://192.168.1.71:9200/test/mytype/_search?pretty -d'{"query":{"match_all":{}}}'   
{                                                                                                                            
  "took" : 5,                                                                                                                
  "timed_out" : false,                                                                                                       
  "_shards" : {                                                                                                              
    "total" : 5,                                                                                                             
    "successful" : 5,                                                                                                        
    "failed" : 0                                                                                                             
  },                                                                                                                         
  "hits" : {                                                                                                                 
    "total" : 2,                                                                                                             
    "max_score" : 1.0,                                                                                                       
    "hits" : [                                                                                                               
      {                                                                                                                      
        "_index" : "test",                                                                                                   
        "_type" : "mytype",                                                                                                  
        "_id" : "2",                                                                                                         
        "_score" : 1.0,                                                                                                      
        "_source" : {                                                                                                        
          "name" : "Dio",                                                                                                    
          "age" : 10                                                                                                         
        }                                                                                                                    
      },                                                                                                                     
      {                                                                                                                      
        "_index" : "test",                                                                                                   
        "_type" : "mytype",                                                                                                  
        "_id" : "1",                                                                                                         
        "_score" : 1.0,                                                                                                      
        "_source" : {                                                                                                        
          "name" : "Paul",                                                                                                   
          "pro" : {                                                                                                          
            "f" : "Cris",                                                                                                    
            "t" : "So"                                                                                                       
          }                                                                                                                  
        }                                                                                                                    
      }                                                                                                                      
    ]                                                                                                                        
  }                                                                                                                          
} 

我可以在λ curl -XGET -u elastic:elasticpassword http://192.168.1.71:9200/test/mytype/_mapping?pretty { "test" : { "mappings" : { "mytype" : { "properties" : { "age" : { "type" : "long" }, "name" : { "type" : "text", "fields" : { "keyword" : { "type" : "keyword", "ignore_above" : 256 } } }, 字段找到,但不能在age字段找到。为什么?

name

1 个答案:

答案 0 :(得分:1)

问题是您的名称字段默认使用标准分析器进行分析,该分析器会对字段进行小写。您可以搜索paul或使用name.keywordPaul字段中搜索。