2017-08-06 101 views
0

這裏搜索是我的索引:通過文本字段

λ 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" : [ ]                                
    }                                    
}                                    

回答

1

問題是,您的姓名字段默認情況下與標準分析儀進行分析,這會降低字段的分辨率。您可以搜索paul或在name.keyword字段搜索Paul

相關問題