通过文本字段

问题描述:

这里搜索是我的索引:通过文本字段

λ 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场。为什么?

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

λ curl -XGET -u elastic:elasticpassword http://192.168.1.71:9200/test/mytype/_search?pretty -d'{"query":{"term":{"name":"Paul"}}}'    
{                                    
    "took" : 5,                                 
    "timed_out" : false,                               
    "_shards" : {                                 
    "total" : 5,                                
    "successful" : 5,                               
    "failed" : 0                                
    },                                   
    "hits" : {                                 
    "total" : 0,                                
    "max_score" : null,                               
    "hits" : [ ]                                
    }                                    
}                                    

问题是,您的姓名字段默认情况下与标准分析仪进行分析,这会降低字段的分辨率。您可以搜索paul或在name.keyword字段搜索Paul