【问题标题】:script doesn't support inline脚本不支持内联
【发布时间】:2016-04-08 11:27:22
【问题描述】:

我正在使用嵌套进行弹性搜索查询。这是我的查询。

 Client.Search<Model>(
                   a =>
                       a.Query(
                           b => b.Bool(c => c.Must(d => d.Script(e => e.Inline("doc['firstname'].value == doc['lastname'].value"))))));

我的目的是获取名字和姓氏相同的记录。但是弹性搜索查询是有意义的。这是那个查询

"query": {
    "filtered": {
       "filter": {
           "script": {
              "script": "doc['firstname'].value == doc['lastname'].value"
           }
       }
    }
    }

但我得到的脚本不支持嵌套的内联响应

【问题讨论】:

  • 你使用什么版本的 NEST 和 elasticsearch?
  • 我使用的是 2.0.5 版本的 Nest
  • 什么版本的 ES,2.x?
  • 当您在浏览器http://localhost:9200 中运行以下请求时会看到什么?
  • 使用 sesne 执行时,它在 localhost:9200 上运行良好。但是巢失败了

标签: elasticsearch nest


【解决方案1】:

Elasticsearch 2.x 中的filtered queries are deprecatedqueries and filters have merged 合并为一个称为查询的概念,根据使用它们的上下文,它们既充当查询又充当过滤器(更简单!)

您可以使用 NEST 2.x 重写您的查询(与 Elasticsearch 2.x 兼容

client.Search<Model>(a => a
    .Query(b => b
        .Bool(c => c
            .Filter(d => d
                .Script(e => e
                    .Inline("doc['firstname'].value == doc['lastname'].value")
                )
            )
        )
    )
);

可以使用查询描述符上的+ 一元运算符进一步缩短

client.Search<Model>(a => a
    .Query(b => +b
        .Script(e => e
            .Inline("doc['firstname'].value == doc['lastname'].value")
        )
    )
);

两者都产生以下查询 json

{
  "query": {
    "bool": {
      "filter": [
        {
          "script": {
            "inline": "doc['firstname'].value == doc['lastname'].value"
          }
        }
      ]
    }
  }
}

Groovy (the default)dynamic scripting is off by default since Elasticsearch 1.4.3,因此您需要为内联脚本启用此功能。

【讨论】:

  • 仍然没有运气.. 得到同样的错误。我在弹性配置中启用了内联脚本。 script.inline: on script.indexed: on
  • 您能否从您的问题的回复中添加.DebugInformation 的值?
  • ServerError: 400Type: search_phase_execution_exception 原因: "所有分片失败" # OriginalException: System.Net.WebException: The remote server returned an error: (400) Bad Request.在 System.Net.HttpWebRequest.GetResponse() 在 Elasticsearch.Net.HttpConnection.Request[TReturn](RequestData requestData) 在 c:\code\elasticsearch-net\src\Elasticsearch.Net\Connection\HttpConnection.cs:line 138 #请求:
  • @user6171782 您能否将上述 DebugInformation 添加到您的问题中?此外,请在您的ConnectionSettings 上设置.DisableDirectStreaming(),以便调试信息将捕获请求和响应
猜你喜欢
  • 2018-08-01
  • 1970-01-01
  • 2023-03-15
  • 2020-03-07
  • 2014-05-21
  • 2021-11-05
  • 2013-09-14
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多