【问题标题】:How can i use kibana visualization query in elasticsearch dsl query?如何在 elasticsearch dsl 查询中使用 kibana 可视化查询?
【发布时间】:2020-06-24 06:08:46
【问题描述】:

我很高兴使用 kibana 查询通过如下过滤来获取数据。

Not why.keyword : "" and target.keyword :"Crystal Sunset Luxury Resort & Spa" and why.keyword : "Kum Plaj,Antalya" and rate >= 0.6

但我决定在 elasticsearch 查询中使用此查询,它会引发错误。如何将上述 kibana 查询转换为简单的 elasticsearch 查询?

GET /hotelsimilarity-*/_search
{
    "query": {
        "query_string": {
            "query": "Not why.keyword : "" and target.keyword :"Crystal Sunset Luxury Resort & Spa" and why.keyword : "Kum Plaj,Antalya" and rate >= 0.6"
        }
    }
}

错误:

{
  "error": {
    "root_cause": [
      {
        "type": "json_parse_exception",
        "reason": "Unexpected character ('\"' (code 34)): was expecting comma to separate Object entries\n at [Source: org.elasticsearch.transport.netty4.ByteBufStreamInput@23dd4c9a; line: 4, column: 43]"
      }
    ],
    "type": "json_parse_exception",
    "reason": "Unexpected character ('\"' (code 34)): was expecting comma to separate Object entries\n at [Source: org.elasticsearch.transport.netty4.ByteBufStreamInput@23dd4c9a; line: 4, column: 43]"
  },
  "status": 500
}

【问题讨论】:

    标签: elasticsearch kibana devops elk


    【解决方案1】:

    您需要通过\" 转义您的字符串,或者您可以使用' 为您的数据加上引号。

    {
        "query": {
            "query_string": {
                "query": "Not why.keyword : '' and target.keyword :'Crystal Sunset Luxury Resort & Spa' and why.keyword : 'Kum Plaj,Antalya' and rate >= 0.6"
            }
        }
    }
    

    错误主要与improper JSON format有关,由mixing " in the query with " in the data引起

    【讨论】:

    • 谢谢,但它不起作用。它返回给我所有水晶等。
    • @penguen 那么有两个问题。一是解决了查询语法错误。但是问题中没有提到另一个。您能否详细说明一下示例文档。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-11-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多