[英]Elasticsearch query_string multivalue fields
我在Ruby on Rails項目的1個中使用ElasticSearch 。 對於ElasticSearch,我大量使用QUERY_STRING
以下是我的項目設置:
Ruby-2.2.4,Rails-4.2.0,ElasticSearch-Model-0.1.8
我已經索引了數據。 使用Article.import
現在,在控制台中,我正在獲取所有已發布的文章數,正在使用:
Article.search(query: { query_string: { query: {"status:1"} } })
這很棒! 現在,我想按user_ids查找文章
上面的SQL就像魅力一樣工作!
SELECT * FROM articles WHERE articles.user_id IN (5, 10)
但是,當我嘗試對query_string使用相同的概念時,它不起作用!
Article.search(query: { query_string: { query: "status:1 AND user_id:[5, 10]" } })
這給了我結果:
Elasticsearch::Transport::Transport::Errors::BadRequest: [400] {"error":"SearchPhaseExecutionException[Failed to execute phase [query], all shards failed; shardFailures {[mUk_rhx-RP6G5sJRMpfDwg][articles][0]: SearchParseException[[articles][0]: from[-1],size[-1]: Parse Failure [Failed to parse source [{\"query\":{\"query_string\":{\"query\":\"status:1 AND user_id:[5,10]\"}}}]]]; nested: QueryParsingException[[articles] Failed to parse query [status:1 AND user_id:[5,10]]]; nested: ParseException[Cannot parse 'status:1 AND user_id:[5,10]': Encountered \" \"]\" \"] \"\" at line 1, column 98.\nWas expecting one of:\n \"TO\" ...\n <RANGE_QUOTED> ...\n <RANGE_GOOP> ...\n ];
請幫助我了解完成這項工作到底需要做什么! 我對此進行了很多搜索,發現了多個選項,例如RANGE,TO等,但沒有一個:(
希望早日收到你的消息!
在這種情況下,您不應使用query_string
。 請改用terms query
。 要合並多個查詢,請使用bool
{
"query": {
"bool": {
"must": [
{
"term": {
"status": 1
}
},
{
"terms": {
"user_id": [
5,
10
]
}
}
]
}
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.