弹性搜索geo_point问题

时间:2015-09-28 18:19:50

标签: node.js elasticsearch mongoosastic

在我的申请中,我使用的是mongoosastic。我创建了Mapping和schema,但是当我看到映射结果时,它会将位置 geo_point 属性更改为对象类型,所以可能因为当我使用查询搜索时它会给我错误:

错误:嵌套:QueryParsingException [[userprofiles]无法找到geo_point字段[location]]; }]“

我提前查询休息客户

创建映射:

"mappings": {
        "userprofile": {
            "properties": {
                "address": {
                    "type": "string"
                },
                "timing": {
                    "type": "object",
                    "properties": {
                        "open": {
                            "type": "string"
                        },
                        "close": {
                            "type": "string"
                        }
                    },
                    "location": {
                        "type": "geo_point"
                    }

                }
            }
        }
    }

用户架构 的

var UserProfileSchema = new Schema({
    userId: String,
    username: String,
    address: {
        type: String,
        es_indexed: true
    },
    number: {
        type: Number,
        es_indexed: true
    },
    location: {
        lat: Number,
        lon: Number
    },
    timing: {
        open: String,
        close: String
    }
});

搜索查询:

{
  "query": {
    "filtered" : {
        "query" : {
            "match_all" : {}
        },
        "filter" : {
            "geo_distance" : {
                "distance" : "20km",
                "location" : {
                    "lat" : 37.9174,
                    "lon" : -122.3050
                }
            }
        }
    }
  }
}

1 个答案:

答案 0 :(得分:0)

您似乎在映射中将location置于timing下。

尝试使用此映射

"mappings": {
        "userprofile": {
            "properties": {
                "address": {
                    "type": "string"
                },
                "timing": {
                    "type": "object",
                    "properties": {
                        "open": {
                            "type": "string"
                        },
                        "close": {
                            "type": "string"
                        }
                    }
                },
                 "location": {
                     "type": "geo_point"
                }
            }
        }
    }