elasticsearch 怎么同时检索单 field 多个值的条件?

2015-05-06 23:34:23 +08:00
 cevincheung

像分类形式的,比如json如下:

[
    {
        "param": "a",
        "field": [
            1,
            2,
            3,
            4,
            5
        ]
    },
    {
        "param": "b",
        "field": [
            1,
            5
        ]
    },
    {
        "param": "c",
        "field": [
            2,
            5
        ]
    },
    {
        "param": "d",
        "field": [
            1,
            3
        ]
    }
]

搜索field同时包含有1和2的。或者包含有3或4的。两种检索条件怎么实现?
求QueryDSL

8040 次点击
所在节点    Elasticsearch
5 条回复
ayang23
2015-05-06 23:52:24 +08:00
bool search, must. 上dsl就没意义了
cevincheung
2015-05-06 23:56:25 +08:00
@ayang23 bool的话又怎么写?多个条件但是都是同一个字段
Gonster
2015-05-07 00:25:59 +08:00
ayang23
2015-05-07 00:27:39 +08:00
{"bool":{"must":[{"term":{"field":1}},{"term":{"field":2}}]}} 应该是这样写
BlueWolf
2015-05-14 20:20:06 +08:00
{
"query_string" : {
"default_field" : "content",
"query" : "this AND that OR thus"
}
}

手册: http://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-query-string-query.html

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/189060

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX