简体   繁体   English

ElasticSearch 上的 Long 类型嵌套查询 (ES 5.0.4)

[英]Nested query on ElasticSearch for Long type (ES 5.0.4)

This is my first question on Stack overflow , please excuse me for the mistakes.这是我关于堆栈溢出的第一个问题,请原谅我的错误。 I will improve on them in the future.将来我会改进它们。 I am new to Elastic Search too.我也是 Elastic Search 的新手。 Okay so I am trying to do a exact match in elastic search (5.0.4).好的,所以我正在尝试在弹性搜索(5.0.4)中进行精确匹配。 Instead of doing an exact match, the request returns all the documents present.请求返回所有存在的文档,而不是完全匹配。 Not sure of this behavior.不确定这种行为。

Here is the mapping这是映射

{
   "properties":{
      "debug_urls":{
         "properties":{
            "characteristics":{
               "type":"text",
               "fields":{
                  "keyword":{
                     "type":"keyword",
                     "ignore_above":256
                  }
               }
            },
            "url_id":{
               "type":"long"
            }
         },
         "type":"nested"
      },
      "scanId":{
         "type":"text",
         "fields":{
            "keyword":{
               "type":"keyword",
               "ignore_above":256
            }
         }
      }
   }
}

This is my request.这是我的要求。

{
    "query": {
        "nested": {
           "path": "debug_urls",
           "query": {
               "match": {
                  "debug_urls.url_id": 1
               }
           }
        }
    }
}

The response received,收到的回复,

{
   "took":1,
   "timed_out":false,
   "_shards":{
      "total":5,
      "successful":5,
      "failed":0
   },
   "hits":{
      "total":1,
      "max_score":1,
      "hits":[
         {
            "_index":"cust_cca39c0c6c8141008e9411032bbf4d21",
            "_type":"debug-urls",
            "_id":"AW70h0l72s9qXitMsWgC",
            "_score":1,
            "_source":{
               "scan_id":"n_a0a523fb5c81435fb79c34c624c7fbd6",
               "debug_urls":[
                  {
                     "url_id":1,
                     "characteristics":[
                        "FORM",
                        "EXTERNAL_SCRIPT",
                        "INLINE_SCRIPT"
                     ]
                  },
                  {
                     "url_id":2,
                     "characteristics":[
                        "EXTERNAL_SCRIPT",
                        "INLINE_SCRIPT"
                     ]
                  },
                  {
                     "url_id":3,
                     "characteristics":[
                        "EXTERNAL_SCRIPT",
                        "INLINE_SCRIPT"
                     ]
                  },
                  {
                     "url_id":4,
                     "characteristics":[
                        "EXTERNAL_SCRIPT",
                        "INLINE_SCRIPT"
                     ]
                  },
                  {
                     "url_id":5,
                     "characteristics":[
                        "EXTERNAL_SCRIPT",
                        "INLINE_SCRIPT"
                     ]
                  },
                  {
                     "url_id":6,
                     "characteristics":[
                        "EXTERNAL_SCRIPT",
                        "INLINE_SCRIPT"
                     ]
                  },
                  {
                     "url_id":7,
                     "characteristics":[
                        "EXTERNAL_SCRIPT",
                        "INLINE_SCRIPT"
                     ]
                  }
               ]
            }
         }
      ]
   }
}

If you only want to see the nested documents that match the criteria, you can leverage nested inner_hits :如果您只想查看符合条件的嵌套文档,您可以利用嵌套的inner_hits

{
    "_source":["scan_id"],                     <--- add this line
    "query": {
        "nested": {
           "path": "debug_urls",
           "query": {
               "match": {
                  "debug_urls.url_id": 1
               }
           },
           "inner_hits": {}                    <--- add this line
        }
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM