elasticsearch嵌套对象数组 - 复杂查询

时间:2017-07-17 09:01:04

标签: elasticsearch spring-data-elasticsearch

好的,这是我的问题: 在后端我有java spring boot,有mongodb和elasticsearch。 我的弹性搜索中有类似这样的文档:

{ "id": 1,
  "prefixes": [
    {
      "prefName": "RS",
      "value": "c"
    },
    {
      "prefName": "99c",
      "value": "c"
    },
    {
      "prefName": "RT",
      "value": "a"
    },
    {
      "prefName": "001b",
      "value": "a"
    },
    {
      "prefName": "DT",
      "value": "m"
    },
    {
      "prefName": "001c",
      "value": "m"
    },
    {
      "prefName": "001d",
      "value": "b"
    },
    {
      "prefName": "RN",
      "value": "16"
    },
    {
      "prefName": "001e",
      "value": "16"
    },
    {
      "prefName": "BN",
      "value": "2-228-32590-2"
    },
    {
      "prefName": "010a",
      "value": "2-228-32590-2"
    },
    {
      "prefName": "SS",
      "value": "d"
    },
    {
      "prefName": "100b",
      "value": "d"
    },
    {
      "prefName": "PY",
      "value": "1975"
    },
    {
      "prefName": "100c",
      "value": "1975"
    },
    {
      "prefName": "LA",
      "value": "fre"
    },
    {
      "prefName": "101a",
      "value": "fre"
    },
    {
      "prefName": "CO",
      "value": "fra"
    },
    {
      "prefName": "102a",
      "value": "fra"
    },
    {
      "prefName": "KW",
      "value": "Ekole et psychologie individuelle comparee"
    }] }

从客户端应用程序我传递具有此结构的对象:

{
"pref1": "(prefixName - value)",
"pref2": "(prefixName - value)",
"pref3": "(prefixName - value)",
"pref4": "(prefixName - value)",
"pref5": "(prefixName - value)",
"text1": "(prefix value - value)",
"text2": "(prefix value - value)",
"text3": "(prefix value - value)",
"text4": "(prefix value - value)",
"text5": "(prefix value - value)",
"operator1": "(logical OR,AND,NOT)",
"operator2": "(logical OR,AND,NOT)",
"operator3": "(logical OR,AND,NOT)",
"operator4": "(logical OR,AND,NOT)"
}

所以,我有5个可选前缀可供选择(pref1,pref2 ...例如RS,RT ..), 文本字段是它们的值,应该与短语前缀匹配。问题是我有4个逻辑运算符链接这些查询。有人可以指导我如何构建足够的elasticsearch查询来满足这些需求。

1 个答案:

答案 0 :(得分:0)

Search form img

这是搜索表单,结果应该是文档: 有前缀AU - Sheakspeare * AND前缀041a - 99c或前缀RN - 23 AND前缀LA NOT 23。