【问题标题】:PartialShardFailureException when trying to filter by GeoDistance (foselasticaBundle Symfony2)尝试按 GeoDistance 过滤时出现 PartialShardFailureException (foselasticaBundle Symfony2)
【发布时间】:2014-09-16 16:26:55
【问题描述】:

几天以来,我的 elastica 查询不再起作用。我没有问题要填充,如果我删除 GeoDistance 部分,请求就会被执行,我会得到结果。目前,在跟踪中,我收到以下消息:

    "message": "1",
    "class": "Elastica\\Exception\\PartialShardFailureException",
    "trace": [
        {
            "namespace": "",
            "short_class": "",
            "class": "",
            "type": "",
            "function": "",
            "file": "/Applications/MAMP/htdocs/GTAB/what2days/api/vendor/ruflin/elastica/lib/Elastica/Transport/Http.php",
            "line": 150,
            "args": []
        }

这对我来说毫无意义,所以我只是创建了一个 $shardsStatistics 变量的 var_export,我明白了:

    array (
        'total' => 6,
        'successful' => 5,
        'failed' => 1,
        'failures' =>
            array (
                0 =>
                    array (
                        'index' => '.marvel-2014.09.16',
                        'shard' => 0,
                        'status' => 400,
                        'reason' => 'SearchParseException[[.marvel-2014.09.16][0]: from[-1],size[-1]: Parse Failure [Failed to parse source [{"query":{"filtered":{"query":{"bool":{"must":[{"term":{"online":{"value":1}}}]}},"filter":{"bool":{"must":[{"geo_distance":{"distance":"100mi","location.latlon":{"lat":48.891773,"lon":2.3379156}}}]}}}}}},"size":"100"}]]]; nested: QueryParsingException[[.marvel-2014.09.16] failed to find geo_point field [location.latlon]]; ',
            ),
        ),
    )

“未能找到 geo_point 字段 [location.latlon]]”的错误结束。我不知道为什么它不起作用,因为当我检查 _mapping 时,geo_point 存在并且我没有弄错属性名称。

    location: {
        properties: {
            latitude: {
                type: "float",
                store: true
            },
            latlon: {
                type: "geo_point",
                store: true,
                lat_lon: true
            },
            longitude: {
                type: "float",
                store: true
            }
        }
    },

这就是我设置 fos_elastica 的方式

fos_elastica:
    clients:
        default: { host: localhost, port: 9200 }
    indexes:
        search:
            finder: ~
            types:
                mytype:
                    mappings:
                        title:
                          type: string
                        online:
                          type: integer
                        information: ~
                        location:
                            type: object
                            properties:
                              longitude:
                                type: float
                              latlon:
                                type: geo_point
                                lat_lon: true
                                boost: 10
                    persistence:
                        driver: orm
                        model:  API\Rest\v1\MyBundle\Entity\MyEntity
                        provider: ~
                    listener: ~
                    finder: ~
                    repository: API\Rest\v1\MyBundle\Repository\MyRepository

当我使用 $query->getQuery() 检索到的查询值(请参阅以下查询)发出 kopf 请求时,我得到正确的结果。

{
    "query": {
        "filtered": {
            "query": {
                "bool": {
                    "must": [
                        {
                            "term": {
                                "online": {
                                    "value": 1
                                }
                            }
                        }
                    ]
                }
            },
            "filter": {
                "bool": {
                    "must": [
                        {
                            "geo_distance": {
                                "distance": "1mi",
                                "location.latlon": {
                                    "lat": 48.891773,
                                    "lon": 2.3379156
                                }
                            }
                        }
                    ]
                }
            }
        }
    }
}

我不知道该怎么办。我在 3.0.*@alpha 版本,现在我正在尝试开发大师。我希望有人能帮我找出问题所在。

当我在 Elastica/Response.php 的 getData 方法中创建一个 var_export 时,我遇到了我之前解释的失败,并且我也有 1 个命中(我想要得到的那个)。

【问题讨论】:

    标签: symfony elasticsearch geolocation elastica


    【解决方案1】:

    我终于找到了解决办法。

    我必须添加一个 index_name 并将 \Elastica\Search 告诉 addIndex('new_index')addType('specific type')

    我以为搜索会自动获得正确的索引,因为我使用的是特定的存储库,但我错了。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-11-16
      • 1970-01-01
      相关资源
      最近更新 更多