es 字段 replace

es 字段 replace 博客分类: 搜索引擎,爬虫

Husk Mit Navn232 丹麦 艺术家 哥本哈根 幽默 纸上 纸上艺术 立体插画 插花艺术 三维 立体感 创意22 脑洞大开 纸艺创意22


type/type/1/_update
{
  "script" : "ctx._source.tagName=ctx._source.tagName.replace(\" 创意22 \",\" 创意55 \")"
}

 

{
    "script" : "ctx._source.tagName = ctx._source.tagName.contains(tag) ? ctx._source.tagName.replace(tag,tag3):ctx._source.tagName.replace(tag2,tag3)",
    "params" : {
        "tag" : " 创意22 ","tag2":"创意22","tag3":" 创意55 "
    }
}

 

{
    "script" : "ctx._source.tagName = ctx._source.tagName.contains(tag) ? ctx._source.tagName.replace(tag,tag3):ctx._source.tagName.replace(tag2,tag3)",
    "script" : "ctx._source.tagName = ctx._source.tagName.contains(tag4) ? ctx._source.tagName.replace(tag4,tag5):ctx._source.tagName.replace(tag4,tag3)",
    "params" : {
        "tag" : " 创意22 ","tag2":"创意22","tag3":" 创意55 ","tag4":" 纸上 ","tag5":"纸上55"
    }
}

 

{
    "script" : "ctx._source.tagName = ctx._source.tagName.contains(tag) ? ctx._source.tagName.replace(tag,tag3):ctx._source.tagName.replace(tag2,tag3)",
    "script" : "ctx._source.tagName2 = ctx._source.tagName.contains(tag4) ? ctx._source.tagName.replace(tag4,tag5):ctx._source.tagName.replace(tag4,tag3)",
    "params" : {
        "tag" : " 创意22 ","tag2":"创意22","tag3":" 创意55 ","tag4":" 纸上 ","tag5":"纸上55"
    },"scripted_upsert":true,
}

 

https://www.elastic.co/guide/en/elasticsearch/reference/1.7/modules-scripting.html#_stored_fields

https://www.elastic.co/guide/en/elasticsearch/reference/1.7/docs-update.html#_literal_doc_as_upsert_literal

https://www.elastic.co/guide/en/elasticsearch/reference/1.7/_updating_documents.html

转载于:https://my.oschina.net/xiaominmin/blog/1599096

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Sure, I can help you with Elasticsearch SQL access. Elasticsearch provides a SQL API that allows you to query data using SQL syntax. To access Elasticsearch using SQL, you need to follow these steps: 1. Install the necessary software: You need to install Elasticsearch and the appropriate version of the Elasticsearch JDBC driver for your programming language or client. 2. Configure Elasticsearch: Enable the SQL feature in your Elasticsearch configuration file. You can do this by setting `xpack.sql.enabled: true` in the `elasticsearch.yml` file. 3. Connect to Elasticsearch: Establish a connection to your Elasticsearch cluster using the JDBC driver. The connection string will depend on your specific setup and programming language. 4. Execute SQL queries: Once connected, you can execute SQL queries against Elasticsearch. The queries can include standard SQL statements like SELECT, INSERT, UPDATE, and DELETE, as well as Elasticsearch-specific extensions for full-text search and complex aggregations. Here's an example of how to query Elasticsearch using SQL in Java: ```java import java.sql.*; public class ElasticsearchSQLAccess { public static void main(String[] args) { Connection conn = null; Statement stmt = null; ResultSet rs = null; try { // Register the JDBC driver Class.forName("org.elasticsearch.xpack.sql.jdbc.EsDriver"); // Open a connection conn = DriverManager.getConnection("jdbc:es://localhost:9200"); // Create a statement stmt = conn.createStatement(); // Execute a query String sql = "SELECT * FROM index_name WHERE field_name = 'value'"; rs = stmt.executeQuery(sql); // Process the result set while (rs.next()) { // Access the retrieved data String field1 = rs.getString("field1"); int field2 = rs.getInt("field2"); // Do something with the data } } catch (SQLException | ClassNotFoundException e) { e.printStackTrace(); } finally { // Close the connections try { rs.close(); } catch (Exception ignored) {} try { stmt.close(); } catch (Exception ignored) {} try { conn.close(); } catch (Exception ignored) {} } } } ``` Remember to replace `index_name`, `field_name`, and the connection details with your actual values. That's a basic overview of how to access Elasticsearch using SQL. You can refer to the Elasticsearch documentation for more information on supported SQL syntax and examples for other programming languages.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值