如何在Elastic Search中基于给定的输入值进行动态弹性搜索查询

时间:2018-12-04 06:12:37

标签: php elasticsearch

我已经用静态值编写了弹性搜索查询,现在我想像具有输入字段一样成为动态对象,基于输入值,我必须进行动态弹性搜索查询。我该怎么做?任何人都请更新我的答案。

  

输入

{
"userID" : "USER1", 
"groupID" : "5b278f8856db693c457b4697", 
"contentType " : "question", 
"contentID" : "5", 
"contentFlow": [
            {
                "contentId": "123",
                "contentType": "topic"
            },
            {
                "contentId": "456",
                "contentType": "concept"
            },
            {
                "contentId": "100",
                "contentType": "sdl"
            }
        ]
      }
  

静态查询

{
   "size":999,
   "query":{
      "bool":{
         "must":[
            {
               "term":{
                  "userId":"USER1"
               }
            },
            {
               "term":{
                  "contentId":"5"
               }
            },
            {
               "bool":{
                  "must":[
                     {
                        "term":{
                           "contentPath.contentType":"topic"
                        }
                     },
                     {
                        "term":{
                           "contentPath.contentId":"123"
                        }
                     }
                  ]
               }
            },
            {
               "bool":{
                  "must":[
                     {
                        "term":{
                           "contentPath.contentType":"concept"
                        }
                     },
                     {
                        "term":{
                           "contentPath.contentId":"456"
                        }
                     }
                  ]
               }
            },
            {
               "bool":{
                  "must":[
                     {
                        "term":{
                           "contentPath.contentType":"sdl"
                        }
                     },
                     {
                        "term":{
                           "contentPath.contentId":"100"
                        }
                     }
                  ]
               }
            }
         ]
      }
   }
}

我刚开始学习弹性搜索,请帮助我解决这个问题

0 个答案:

没有答案
相关问题