我如何使用" update_by_query"更新数据?在Elasticsearch 2.x?

时间:2016-07-13 08:04:07

标签: elasticsearch

我需要通过一些查询弹性更新多个更新文档。我找到了一个解决方案像这样:

{
    "query": {
        "term": {
            "name": "some name"
        }
    },
    "script": {
        "inline": "ctx._source.some_field = \"value\""
    }
}

但它并不完全是我需要的。例如,一个请求将更新10个或20个字段。因此,生成"脚本"令人不舒服。许多字段的字符串。理想情况下,我需要这样的东西:

{
    "query": {
        "term": {
            "name": "some name"
        }
    },
    "doc": {
        "field1": "value1",
        "field2": "value2",
        "field3": "value3",
        "field4": "value4",
        "field5": "value5",
        ...
        "fieldN": "valueN",
    }
}

为了实现上述内容,我希望有另一种选择

1 个答案:

答案 0 :(得分:1)

您可以使用如下脚本:

 <RelativeLayout xmlns:androclass="http://schemas.android.com/apk/res/android"  
        xmlns:tools="http://schemas.android.com/tools"  
        android:layout_width="match_parent"  
        android:layout_height="match_parent"  
        tools:context=".MainActivity" >  

        <VideoView  
            android:id="@+id/videoView1"  
            android:layout_width="wrap_content"  
            android:layout_height="wrap_content"  
            android:layout_alignParentLeft="true"  
            android:layout_centerVertical="true" />  

    </RelativeLayout>