【问题标题】:Elasticsearch multisearch returns wrong response but single query returns correct responseElasticsearch 多搜索返回错误响应,但单个查询返回正确响应
【发布时间】:2017-06-06 17:59:37
【问题描述】:

使用官方 python 客户端在 Elasticsearch 上运行以下查询会返回错误的响应,但单独运行它们会给出正确的响应。

以下对象作为 search_doc 传递给elasticsearch.msearch()

[
  {
    'type': 1,
    'index': 'xyz'
  },
  {
    'query': {
      'bool': {
        'must': [
          {
            'match_phrase': {
              'messageid': 'DEL_1CKCJAR'
            }
          },
          {
            'regexp': {
              'dsn': '2.[0-9].[0-9]'
            }
          }
        ]
      }
    }
  },
  {
    'type': 1,
    'index': 'xyz'
  },
  {
    'query': {
      'bool': {
        'must': [
          {
            'match_phrase': {
              'messageid': 'DEL_1CKCJAR'
            }
          },
          {
            'regexp': {
              'dsn': '5.[0-9].[0-9]'
            }
          }
        ]
      }
    }
  },
  {
    'type': 1,
    'index': 'xyz'
  },
  {
    'query': {
      'bool': {
        'must': [
          {
            'match_phrase': {
              'messageid': 'DEL_1CKCJAR'
            }
          },
          {
            'regexp': {
              'dsn': '4.[0-9].[0-9]'
            }
          }
        ]
      }
    }
  }
]

并返回以下响应:

[
  {
    'took': 42,
    'hits': {
      'hits': [

      ],
      'total': 0,
      'max_score': None
    },
    'status': 200,
    'timed_out': False,
    '_shards': {
      'failed': 0,
      'total': 5,
      'successful': 5
    }
  },
  {
    'took': 41,
    'hits': {
      'hits': [

      ],
      'total': 0,
      'max_score': None
    },
    'status': 200,
    'timed_out': False,
    '_shards': {
      'failed': 0,
      'total': 5,
      'successful': 5
    }
  },
  {
    'took': 41,
    'hits': {
      'hits': [

      ],
      'total': 0,
      'max_score': None
    },
    'status': 200,
    'timed_out': False,
    '_shards': {
      'failed': 0,
      'total': 5,
      'successful': 5
    }
  }
]

但是,在索引xyz 上单独运行,查询如下:

{
  'query': {
    'bool': {
      'must': [
        {
          'match_phrase': {
            'messageid': 'DEL_1CKCJAR'
          }
        },
        {
          'regexp': {
            'dsn': '4.[0-9].[0-9]'
          }
        }
      ]
    }
  }
}

返回以下响应:

{
  "took": 6,
  "timed_out": false,
  "_shards": {
    "total": 5,
    "successful": 5,
    "failed": 0
  },
  "hits": {
    "total": 18,
    "max_score": 2.7300916,
    "hits": [
      {
        "_index": "xyz",
        "_type": "log",
        "_id": "3A91F141442",
        "_score": 2.7300916,
        "_source": {
          "pid": "13034",
          "type": "log",
          "logsource": "localhost",
          "qid": "3A91F141442",
          "@timestamp": "2017-06-05T16:44:16.177Z",
          "@version": "1",
          "host": "localhost.localdomain",
          "client": "unknown[XXX.XXX.XXX.XXX]",
          "messageid": "20170606062113.12268.36913.DEL_1CKCJAR@localhost.localdomain>",
          "nrcpt": "1",
          "queuestatus": "queue active",
          "size": "1297",
          "from": "asdfasdfasdf@gmail.com",
          "reason": "(connect to mx2.hotmail.com[XXX.XXX.XXX.XXX]:25: Connection timed out)",
          "relayhost": "none",
          "result": "deferred",
          "delay": "8707",
          "to": "abcdefg@outlook.com",
          "dsn": "4.4.1"
        }
      },
    ....
}

,这是所需的响应。到目前为止,我无法弄清楚为什么单个请求有效但 multi_search 请求无效。

注意:正在搜索的数据是 Elasticsearch 日志数据。

感谢任何帮助。 :)

【问题讨论】:

    标签: python elasticsearch elasticsearch-py


    【解决方案1】:

    我会说您的多重搜索查询使用了错误的type

    {
        'type': 1,
        'index': 'xyz'
    }
    

    单个搜索查询返回的文档类型为log。要么完全省略类型,要么使用log,您的查询应该返回所需的结果。

    【讨论】:

    • 谢谢。当我更改日志的文档类型时,忘记更改搜索查询中的类型。不应该错过。
    猜你喜欢
    • 1970-01-01
    • 2011-03-27
    • 2017-08-10
    • 1970-01-01
    • 2019-05-26
    • 2011-02-24
    • 1970-01-01
    • 2014-12-18
    • 1970-01-01
    相关资源
    最近更新 更多