Fatih Aktepe
Fatih Aktepe

Reputation: 601

Elasticsearch Parse Exception for boolean queries

I'm trying to create queries similar to kibana queries in elasticsearch lucene queries. What I'm basically trying to do is matching some phrases. For example; my kibana query looks like this:(+"anna smith") AND ( (+"university"), (+"chairman"), (+"women rights")) It searches "anna smith" as must and one of the other phrases as should(there should be at least one of them exist in the text). I wrote a query to do this but it gives "elasticsearch parse exception:expected field name but got start_object". How can I solve this. Here is my query;

{
    "query": {
        "bool": {
            "must": {
                "match": {  
                    "text": {
                        "query":    "anna smith",
                        "operator": "and"
                    }
                }
              }
            },
             "query": {
                "bool": {
                    "must": [
                    {
                    "bool": {
                    "should": [
                        { 
                            "match": {
                            "text": {
                                "query": "university",
                                "boost": 2 
                            }
                        }

                        },
                        { 
                            "match": {
                            "text": {
                                "query": "chairman",
                                "boost": 2 
                                    }
                                  }
                        }
            ]
        }
    }]
}}}}

Upvotes: 0

Views: 240

Answers (1)

Val
Val

Reputation: 217344

Your second query at the bottom cannot be there, it needs to be inside the first bool/must like this

{
  "query": {
    "bool": {
      "must": [
        {
          "match": {
            "text": {
              "query": "anna smith",
              "operator": "and"
            }
          }
        },
        {
          "bool": {
            "should": [
              {
                "match": {
                  "text": {
                    "query": "university",
                    "boost": 2
                  }
                }
              },
              {
                "match": {
                  "text": {
                    "query": "chairman",
                    "boost": 2
                  }
                }
              }
            ]
          }
        }
      ]
    }
  }
}

Upvotes: 1

Related Questions