【问题标题】:Elastic-search & Nest query弹性搜索和嵌套查询
【发布时间】:2017-06-11 23:53:09
【问题描述】:

如何查询所有包含特定字符串的记录?

例如:

如果那些在分贝

{
"ip": "185.239.131.76",
"domain": "http://express.com",
"event_type": "page_view"
},
{
"ip": "185.239.131.76",
"domain": "http://express.com",
"event_type": "page_view"
},
{
"ip": "37.39.244.71",
"domain": "http://express.com",
"event_type": "view"
},

我想获取包含字符串“page”的所有记录

所以我只得到了上面 3 条记录中的前 2 条记录?

还能显示http查询和nest查询吗?

谢谢

【问题讨论】:

  • 向我们展示您的 http 查询和嵌套查询..

标签: elasticsearch nest


【解决方案1】:

如果我正确理解了您的问题,您有一个字段 event_type,其中包含 page_viewview 之类的值,也可能是 page_action,但值是单个字符串。

我在event_type 中查询page 的方法是将event_type 映射为not_analyzed,如下图mapping

"event_type": {
  "index": "not_analyzed",
  "type": "string"
},

然后查询以page开头的字符串,比如

GET yourIndex/_search
{ "query": {
    "prefix": {
      "event_type": {
          "value": "page"
      }
    }
}

【讨论】:

    【解决方案2】:

    你可以试试发帖查询:

    http://localhost:9200/YourIndex/_search?=pretty=true

    查询:

    {
        "query": {
            "match": {
                "event_type": "page_view"
            }
        }
    

    【讨论】:

      猜你喜欢
      • 2021-09-01
      • 2015-09-24
      • 2020-07-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-09-28
      相关资源
      最近更新 更多