Elasticsearch没有按预期过滤

时间:2017-02-22 09:25:33

标签: elasticsearch

我正在使用Elasticsearch 1.4

我有一个索引:

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}
                    }
                }
            }]
        }
    }
}

上面的查询不会返回数据但是当我删除以下术语时它会返回数据:

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

请告诉我这个问题,感谢任何建议!

1 个答案:

答案 0 :(得分: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"
        }
      }
    }
  }
}'
相关问题