0
votes

I have some problem with the elasticsearch query. when I use the query code it feedback the messages [bool] malformed query, expected [END_OBJECT] but found [FIELD_NAME].

{  
   "from":0,
   "size":15,
   "query":{  
      "bool":{  
         "must":[  
            {  
               "multi_match":{  
                  "query":"books",
                  "fields":[  
                     "title^20",
                     "lead^10",
                     "content"
                  ],
                  "type":"phrase"
               }
            }
         ]
      },
      "must":{  
         "match":{  
            "groupid":"599e4b49239cfa0a5a5f189d"
         }
      }
   },
   "sort":[  
      {  
         "times":{  
            "order":"desc"
         }
      }
   ]
}
1

1 Answers

4
votes

Your second must clause is not properly located, it must be inside the existing bool/must query. You need to rewrite your query to this:

{  
   "from":0,
   "size":15,
   "query":{  
      "bool":{  
         "must":[  
            {  
               "multi_match":{  
                  "query":"books",
                  "fields":[  
                     "title^20",
                     "lead^10",
                     "content"
                  ],
                  "type":"phrase"
               }
            },
            {  
               "match":{  
                  "groupid": "599e4b49239cfa0a5a5f189d"
               }
            }
         ]
      }
   },
   "sort":[  
      {  
         "times":{  
            "order":"desc"
         }
      }
   ]
}