0

I am trying to make full-text search in whole document using

"query" => [
    "query_string" => [
        "fields" => ["_all"],
        "query" => "fooA AND fooB"
    ]
]

It works pretty good. In the same query I need to run bool query

"query" => [
    "bool" => [
        "must" => [
            "term" => [
                "name" => "My_name"
            ]
        ],
        "should" => [
            ....
        ]
    ]
]

Is it possible to combine these two queries ? is this proper way to make full-text search ?

In result I need all documents that contains "fooA AND fooB" in any field and special field name equals "My_name".

OdkoPP
  • 442
  • 6
  • 14

2 Answers2

0

Yes, you can club these together as shown below :

GET _search
{
  "from": 0,
  "size": 20,
  "query": {
    "bool": {
      "must": [
        {
          "term": {
            "name": "MY_NAME"
          }
        },
        {
          "query_string": {
            "query": "fooA AND fooB",
            "fields": [
              "_all"
            ]
          }
        }
      ]
    }
  }
}
Rahul
  • 15,979
  • 4
  • 42
  • 63
0

I found solution for my question thanks to this post.

"query" => [
    "bool" => [
        "must" => [
            [
                "term" => [
                    "name" => "My_name"
                ]
            ],
            [
                "query_string" => [
                    "fields" => ["_all"],
                    "query" => "fooA AND fooB"
                ]
            ]
        ]
    ]
]

This combination works for me

Community
  • 1
  • 1
OdkoPP
  • 442
  • 6
  • 14