2017-02-22 134 views
0

我使用Elasticsearch 1.4Elasticsearch不过滤

我有一个指标:

curl -XPUT "http://localhost:49200/customer" -d '{"mappings": {"venues": {"properties": {"party_id": {"type": "string"},"sup_party_id": {"type": "string"},"location": {"type": "geo_point"}   }  } }}' 

而且把一些数据,实例:

curl -XPOST "http://localhost:49200/customer/venues/RO2" -d '{ "party_id":"RO2", "sup_party_id": "SUP_GT_R1A_0001","location":{ "lat":"21.030347","lon":"105.842896" }}' 
curl -XPOST "http://localhost:49200/customer/venues/RO3" -d '{ "party_id":"RO3", "sup_party_id": "SUP_GT_R1A_0004","location":{ "lat":"20.9602051","lon":"105.78709179999998" }}' 

,我的过滤器是:

{"constant_score": 
    {"filter": 
     {"and": 
      [{"terms": 
       {"sup_party_id":["SUP_GT_R1A_0004","SUP_GT_R1A_0001","RO2","RO3","RO4"] 
       } 
      },{"geo_bounding_box": 
       {"location": 
        {"top_left":{"lat":25.74546096707413,"lon":70.43503197075188}, 
        "bottom_right":{"lat":6.342579199578783,"lon":168.96042259575188} 
        } 
       } 
      }] 
     } 
    } 
} 

the上面的查询不返回数据,但它返回数据时,我删除了以下条款:

{"terms": 
    {"sup_party_id":["SUP_GT_R1A_0004","SUP_GT_R1A_0001","RO2","RO3","RO4"] 
    } 
} 

请告诉我这个问题,有什么建议表示赞赏!

回答

1

这是因为sup_party_id字段是经过分析的字符串。改为像这样的映射,而不是它,它会工作:

curl -XPUT "http://localhost:49200/customer" -d '{ 
    "mappings": { 
    "venues": { 
     "properties": { 
     "party_id": { 
      "type": "string" 
     }, 
     "sup_party_id": { 
      "type": "string", 
      "index": "not_analyzed"  <--- add this 
     }, 
     "location": { 
      "type": "geo_point" 
     } 
     } 
    } 
    } 
}' 
+0

对不起,延迟的答复,它工作正常。非常感谢你! –

+0

真棒,很高兴它解决了! – Val