msearch不能与bool一起工作

时间:2013-06-08 02:03:10

标签: full-text-search elasticsearch

Elasticsearch版本 - .90.1

以下作品完美无缺。

cat names
{"index":"events","type":"news"}
{"query":{"term":{"Type":"MarketEvent"}}}
{"query":{"term":{"Type":"MarketEvent"}}}

curl -XGET 'http://localhost:9200/_msearch'  --data-binary @names

以下也适用

{"index":"events","type":"news"}
{"query":{"bool":{"must":[{"query_string":{"query":"*","fields":["Events.Event"],"default_operator":"AND"}},{"term":{"Type":"MarketEvent"}}]}}}

但是超过1个bool的查询不起作用 -

cat names
{"index":"events","type":"news"}
{"query":{"bool":{"must":[{"query_string":{"query":"*","fields":["Events.Event"],"default_operator":"AND"}},{"term":{"Type":"MarketEvent"}}]}}}
{"query":{"bool":{"must":[{"query_string":{"query":"*","fields":["Events.Event"],"default_operator":"AND"}},{"term":{"Type":"MarketEvent"}}]}}}

curl -XGET 'http://localhost:9200/_msearch'  --data-binary @names
{"error":"must doesn't support arrays"}

我没有在日志中看到任何日志(也没有在DEBUG模式下) 这是一个错误吗?

1 个答案:

答案 0 :(得分:3)

_msearch查询应具有以下格式:

header\n
body\n
header\n
body\n

在第一个和最后一个查询中,缺少第二个标头。由于解析标头的方式,不会为第一个查询生成错误。要使此查询生效,names文件应更改为

{"index":"events","type":"news"}
{"query":{"bool":{"must":[{"query_string":{"query":"*","fields":["Events.Event"],"default_operator":"AND"}},{"term":{"Type":"MarketEvent"}}]}}}
{"index":"events","type":"news"}
{"query":{"bool":{"must":[{"query_string":{"query":"*","fields":["Events.Event"],"default_operator":"AND"}},{"term":{"Type":"MarketEvent"}}]}}}