小编Aks*_*awe的帖子

使用Java在Elasticsearch中按查询更新

我目前正在使用Elasticsearch V2.3.1.我想在Java中使用以下Elasticsearch查询.

POST /twitter/_update_by_query
{
  "script": {
    "inline": "ctx._source.List = [‘Item 1’,’Item 2’]”
  },
  "query": {
    "term": {
      "user": "kimchy"
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

上述查询搜索名为"kimchy"的"user",并使用给定值更新"List"字段.此查询同时更新多个文档.我在这里阅读了有关Java的更新API https://www.elastic.co/guide/en/elasticsearch/client/java-api/2.3/java-docs-update.html但找不到我要找的内容.Java的Update API仅讨论一次更新单个文档.有没有办法更新多个文件?对不起,如果我错过了一些明显的东西.感谢您的时间.

更新:

我尝试了下面的Java代码:

Client client = TransportClient.builder().addPlugin(ReindexPlugin.class)
    .build().addTransportAddress(new InetSocketTransportAddress(
        InetAddress.getByName("127.0.0.1"), 9300));

UpdateByQueryRequestBuilder ubqrb = UpdateByQueryAction.INSTANCE
    .newRequestBuilder(client);

Script script = new Script("ctx._source.List = [\"Item 1\",\"Item 2\"]");

//termQuery is not recognised by the program
BulkIndexByScrollResponse r = ubqrb.source("twitter").script(script)
    .filter(termQuery("user", "kimchy")).execute().get();
Run Code Online (Sandbox Code Playgroud)

所以我编辑了如上所述的Java程序,并且Java不识别termQuery.我可以知道我在这里做错了吗?谢谢.

java elasticsearch elasticsearch-java-api

8
推荐指数
1
解决办法
7507
查看次数

Elasticsearch的实际得分是不同的解释得分

我在Elasticsearch中运行了一个带有解释的查询.解释的最终得分是7.0064363,但查询的实际得分仅为0.6251602.

Elasticsearch在解释和实际得分之间做了什么导致得分如此不同?任何帮助,将不胜感激.

以下是搜索结果的摘要:

  {
    "_shard": 4,
    "_node": "KjOdjnQqQ-yQ3a0hvhlTcA",
    "_index": "index",
    "_type": "type",
    "_id": "id",
    "_score": 0.6251602,
    "_source": {
      .....
    },
    "_explanation": {
      "value": 7.0064363,
      "description": "product of:",
      "details": [
        {
          "value": 12.845133,
          "description": "sum of:",
          "details": [
          ........
          ]
        },
        {
          "value": 0.54545456,
          "description": "coord(6/11)",
          "details": []
        }
      ]
    }
  },

lucene elasticsearch

5
推荐指数
0
解决办法
334
查看次数