0

I have make the application with elasticsearch and everything is running perfectly except the search using the php curl; the error is below

[match] query parsed in simplified form, with direct field name, but included more options than just the field name, possibly use its 'options' form, with 'query' element?]

but the same query is running perfectly in the command-line.

When I do some changes, I found this is occurring by the curl POST.

I am using the following code to run the php curl and tried the GET method too

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_TIMEOUT, 200);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, strtoupper($method));
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($params));
$response = curl_exec($ch);
curl_close ($ch);

and the query is

{"query":{"filtered":{"query":{"bool":{"should":[{"bool":{"should":[{"match_phrase":{"name":"india"}}],"boost":16}},{"bool":{"should":[{"match_phrase":{"description":"india"}}],"boost":8}},{"bool":{"should":[{"match":{"name":{"query":"india","analyzer":"standard"}}},{"match":{"description":{"query":"india","analyzer":"standard"}}}],"boost":4}},{"match":{"name.ngram":[{"query":"india","analyzer":"standard"}]}},{"match":{"description":[{"query":"india","analyzer":"standard"}]}},{"match":{"name.ngram":[{"query":"india","analyzer":"standard","fuzziness":"auto"}]}},{"match":{"description":[{"query":"india","analyzer":"standard","fuzziness":"auto"}]}}],"boost":2}},"filter":{"and":[{"terms":{"type":["book"]}},{"range":{"price":{"from":"1","to":"100"}}}]}}},"from":0,"size":20,"filter":{"and":[]},"sort":[{"popularity":{"order":"desc","missing":"_last"}}]}
2
  • 1
    What is your query? I.e. what do you pass as $params? Commented Mar 13, 2015 at 9:59
  • @king_nak i have updated the question; please find the query now Commented Mar 13, 2015 at 10:23

2 Answers 2

1

Problem might be in you are using blank filters in your query dsl.

"filter": {
    "and":[]
}

Try without blank filters. Also top level filters are renamed in Elasticsearch 1.0 + version.

Update Query DSL:

{
   "query": {
      "filtered": {
         "query": {
            "bool": {
               "should": [
                  {
                     "bool": {
                        "should": [
                           {
                              "match_phrase": {
                                 "name": "india"
                              }
                           }
                        ],
                        "boost": 16
                     }
                  },
                  {
                     "bool": {
                        "should": [
                           {
                              "match_phrase": {
                                 "description": "india"
                              }
                           }
                        ],
                        "boost": 8
                     }
                  },
                  {
                     "bool": {
                        "should": [
                           {
                              "match": {
                                 "name": {
                                    "query": "india",
                                    "analyzer": "standard"
                                 }
                              }
                           },
                           {
                              "match": {
                                 "description": {
                                    "query": "india",
                                    "analyzer": "standard"
                                 }
                              }
                           }
                        ],
                        "boost": 4
                     }
                  },
                  {
                     "match": {
                        "name.ngram": [
                           {
                              "query": "india",
                              "analyzer": "standard"
                           }
                        ]
                     }
                  },
                  {
                     "match": {
                        "description": [
                           {
                              "query": "india",
                              "analyzer": "standard"
                           }
                        ]
                     }
                  },
                  {
                     "match": {
                        "name.ngram": [
                           {
                              "query": "india",
                              "analyzer": "standard",
                              "fuzziness": "auto"
                           }
                        ]
                     }
                  },
                  {
                     "match": {
                        "description": [
                           {
                              "query": "india",
                              "analyzer": "standard",
                              "fuzziness": "auto"
                           }
                        ]
                     }
                  }
               ],
               "boost": 2
            }
         },
         "filter": {
            "and": [
               {
                  "terms": {
                     "type": [
                        "book"
                     ]
                  }
               },
               {
                  "range": {
                     "price": {
                        "from": "1",
                        "to": "100"
                     }
                  }
               }
            ]
         }
      }
   },
   "from": 0,
   "size": 20,
   "sort": [
      {
         "popularity": {
            "order": "desc",
            "missing": "_last"
         }
      }
   ]
}
Sign up to request clarification or add additional context in comments.

1 Comment

I have updated the query given by you and its also giving the same error
1

I found the solution; below is the correct json

{"query":{"filtered":{"query":{"bool":{"should":[{"bool":{"should":[{"match_phrase":{"name":"india"}}],"boost":16}},{"bool":{"should":[{"match_phrase":{"description":"india"}}],"boost":8}},{"bool":{"should":[{"match":{"name":{"query":"india","analyzer":"standard"}}},{"match":{"description":{"query":"india","analyzer":"standard"}}}],"boost":4}},{"match":{"name.ngram":{"query":"india","analyzer":"standard"}}},{"match":{"description":{"query":"india","analyzer":"standard"}}},{"match":{"name.ngram":{"query":"india","analyzer":"standard","fuzziness":"auto"}}},{"match":{"description":{"query":"india","analyzer":"standard","fuzziness":"auto"}}}],"boost":2}},"filter":[]}},"from":0,"size":20,"sort":[{"popularity":{"order":"desc","missing":"_last"}}]}

the problem is in the match query phase; I was appending the parameters in match query as nested array.

Now I have removed the nested array and append the options in match query phase as sequential array

Thanks guys for your co-opration

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.