首页 > 解决方案 > elasticsearch返回要触发的对象的空列表

问题描述

我对Elasticsearch有疑问。

我想用Pyspark从Elasticsearch索引中读取数据。我的数据如下所示:

user_id: 123,
features: {
    hashtags: [
        {
            text: "hello",
            count: 2
        },
        {
            text: "world",
            count: 1
        }
    ]
}
...

当数据加载时, Elasticsearch似乎返回空的对象列表。读取后我的数据框如下所示:

+----------+-------------------+
|  features|            user_id|
+----------+-------------------+
|{[{}, {}]}|                123|
|    {[{}]}|                384|
|    {[{}]}|                 94|
|{[{}, {}]}|                880|
+----------+-------------------+

我使用此配置从弹性读取数据:

tweets = sqlContext.read.format("org.elasticsearch.spark.sql") \
    .option("es.nodes", "localhost") \
    .option("es.port", "9200") \
    .option("es.read.field.as.array.include", "features.hashtags")\
    .option("es.read.field.include", "user_id, features.hashtags")\
    .option("es.resource", "twitter")\
    .load().limit(10)

你能帮我解决吗?

标签: apache-sparkelasticsearchpyspark

解决方案


推荐阅读