【问题标题】:only one of the identical query is executed successfully in elastic search?在弹性搜索中只有一个相同的查询成功执行?
【发布时间】:2021-11-22 11:12:15
【问题描述】:

您好,我有一个在 docker 容器中运行的弹性搜索实例。我有两个查询,每个查询都放在一个文件中,即 query6.json 和 query7.json。两个文件都包含相同的查询。

当我使用 curl 命令运行其中一个查询时,它会提供结果。

curl -XGET http://localhost:55083/mep-reports*/_search?pretty -H "Content-Type: application/json" -d @query6.json 

上述查询的结果返回如下结果

{
  "took": 10,
  "timed_out": false,
  "_shards": {
    "total": 1,
    "successful": 1,
    "skipped": 0,
    "failed": 0
  },
  "hits": {
    "total": {
      "value": 100,
      "relation": "eq"
    },
    "max_score": null,
    "hits": [
      {
        "_index": "mep-reports",
        "_type": "_doc",
        "_id": "nMQ0N3wBcQytyR4tsuFr",
        "_score": null,
        "_source": {
          "inventory": "SMS",
          "msg_text": "This is random text",
          "status": "ENROUTE",
          "@timestamp": "2019-09-10T07:06:26.287Z",
          "o_error": "",
          "flight_id": "92348fa1-ca6c-456a-b3b2-85fba2d2deed",
          "recipient": "420736408281",
          "account_id": "a56f7e14-20f9-40e6-90c6-10604140ac5f",
          "sender": "8800111",
          "campaign_id": "6f2abca3-b46d-43f3-91be-3278a8dd7dc0",
          "nof_segments": 1,
          "@version": 1,
          "submission_ts": 1568105380000000,
          "delivery_ts": 1553616888000000,
          "campaign_name": "Starbucks Promotion",
          "flight_name": "Extremely very very long flight",
          "campaign_type": "NON_MARKETING",
          "created_by": "0c9d6015-f45f-4a90-a58c-8c99384aa40",
          "first_name": "Campaign",
          "last_name": "Manager"
        },
        "sort": [
          1568099186287
        ]
      },
      {
        "_index": "mep-reports",
        "_type": "_doc",
        "_id": "k8Q0N3wBcQytyR4tsuFr",
        "_score": null,
        "_source": {
          "inventory": "SMS",
          "msg_text": "This is random text",
          "status": "ENROUTE",
          "@timestamp": "2019-09-09T20:45:32.087Z",
          "o_error": "",
          "flight_id": "92348fa1-ca6c-456a-b3b2-85fba2d2deed",
          "recipient": "420736408283",
          "account_id": "a56f7e14-20f9-40e6-90c6-10604140ac5f",
          "sender": "8800111",
          "campaign_id": "6f2abca3-b46d-43f3-91be-3278a8dd7dc0",
          "nof_segments": 1,
          "@version": 1,
          "submission_ts": 1568105380000000,
          "delivery_ts": 1563144156000000,
          "campaign_name": "Starbucks Promotion",
          "flight_name": "Short Flight",
          "campaign_type": "NON_MARKETING",
          "created_by": "0c9d6015-f45f-4a90-a58c-8c99384aa40",
          "first_name": "Campaign",
          "last_name": "Manager"
        },
        "sort": [
          1568061932087
        ]
      }
    ]
  }
}

当我从第二个文件运行第二个查询时,它不返回任何结果

 curl -XGET http://localhost:55083/mep-reports*/_search?pretty -H "Content-Type: application/json" -d @query7.json 

输出

{
  "took" : 4,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 0,
      "relation" : "eq"
    },
    "max_score" : null,
    "hits" : [ ]
  }
}

我比较了工具中的文件,结果似乎相同。

我也做了一个比较,结果如下。

diff query6.json query7.json 
47,50c47,53
<        {
<          "terms": {
<                "created_by": ["0c9d6015-f45f-4a90-a58c-8c99384aa40","0c9d6015-f45f-4a90-a58c-8c99384aa41"]           }
<        }
---
>         {
>           "terms": {
>             "created_by": [
>               "0c9d6015-f45f-4a90-a58c-08c99384aa40", "0c9d6015-f45f-4a90-a58c-08c99384aa41"
>             ]
>           }
>         }

就内容而言,这些文件似乎相同。

请在此处查找文件

query6.json

{
  "from": 0,
  "size": 10,
  "timeout": "300s",
  "query": {
    "bool": {
      "must": [
        {
          "range": {
            "@timestamp": {
              "from": "2019-08-31T23:00:00.000Z",
              "to": null,
              "include_lower": true,
              "include_upper": true,
              "format": "yyyy-MM-dd'T'HH:mm:ss.SSSX",
              "boost": 1.0
            }
          }
        },
        {
          "range": {
            "@timestamp": {
              "from": null,
              "to": "2019-09-12T07:06:26.287Z",
              "include_lower": true,
              "include_upper": true,
              "format": "yyyy-MM-dd'T'HH:mm:ss.SSSX",
              "boost": 1.0
            }
          }
        },
        {
          "match": {
            "account_id": {
              "query": "a56f7e14-20f9-40e6-90c6-10604140ac5f",
              "operator": "OR",
              "prefix_length": 0,
              "max_expansions": 50,
              "fuzzy_transpositions": true,
              "lenient": false,
              "zero_terms_query": "NONE",
              "auto_generate_synonyms_phrase_query": true,
              "boost": 1.0
            }
          }
        },
       {
         "terms": {
               "created_by": ["0c9d6015-f45f-4a90-a58c-8c99384aa40","0c9d6015-f45f-4a90-a58c-8c99384aa41"]           }
       }
      ],
      "adjust_pure_negative": true,
      "boost": 1.0
    }
  },
  "sort": [
    {
      "@timestamp": {
        "order": "desc"
      }
    }
  ]
}

query7.json

{
  "from": 0,
  "size": 10,
  "timeout": "300s",
  "query": {
    "bool": {
      "must": [
        {
          "range": {
            "@timestamp": {
              "from": "2019-08-31T23:00:00.000Z",
              "to": null,
              "include_lower": true,
              "include_upper": true,
              "format": "yyyy-MM-dd'T'HH:mm:ss.SSSX",
              "boost": 1.0
            }
          }
        },
        {
          "range": {
            "@timestamp": {
              "from": null,
              "to": "2019-09-12T07:06:26.287Z",
              "include_lower": true,
              "include_upper": true,
              "format": "yyyy-MM-dd'T'HH:mm:ss.SSSX",
              "boost": 1.0
            }
          }
        },
        {
          "match": {
            "account_id": {
              "query": "a56f7e14-20f9-40e6-90c6-10604140ac5f",
              "operator": "OR",
              "prefix_length": 0,
              "max_expansions": 50,
              "fuzzy_transpositions": true,
              "lenient": false,
              "zero_terms_query": "NONE",
              "auto_generate_synonyms_phrase_query": true,
              "boost": 1.0
            }
          }
        },
        {
          "terms": {
            "created_by": [
              "0c9d6015-f45f-4a90-a58c-08c99384aa40", "0c9d6015-f45f-4a90-a58c-08c99384aa41"
            ]
          }
        }
      ],
      "adjust_pure_negative": true,
      "boost": 1.0
    }
  },
  "sort": [
    {
      "@timestamp": {
        "order": "desc"
      }
    }
  ]
}

如果您能提供帮助,不胜感激 谢谢

【问题讨论】:

    标签: elasticsearch elasticsearch-dsl


    【解决方案1】:

    这里有区别:

    {
       "terms":{
          "created_by":[
             "0c9d6015-f45f-4a90-a58c-8c99384aa40",
             "0c9d6015-f45f-4a90-a58c-8c99384aa41"
          ]
       }
    }
    
    {
       "terms":{
          "created_by":[
             "0c9d6015-f45f-4a90-a58c-08c99384aa40",
             "0c9d6015-f45f-4a90-a58c-08c99384aa41"
          ]
       }
    }
    

    额外的0 字符。

    【讨论】:

    • 由于以下 System.out.println(UUID.fromString( "0c9d6015-f45f-4a90-a58c-8c99384aa40")); 添加了额外的字符------------ 输出为 0c9d6015-f45f-4a90-a58c-08c99384aa40
    猜你喜欢
    • 2016-10-25
    • 1970-01-01
    • 2021-01-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-06-12
    • 2016-07-20
    • 1970-01-01
    相关资源
    最近更新 更多