0

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 
                                    }
                                  }
                        }
            ]
        }
    }]
}}}}

1 Answer 1

1

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
                  }
                }
              }
            ]
          }
        }
      ]
    }
  }
}
Sign up to request clarification or add additional context in comments.

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.