简体   繁体   中英

Elasticsearch 2.x to 5.x query issue

The below query needs to be changed from version 2.x to version 5.x.

filtered => bool

But should is not supporting multiple queries.

"query": {
    "filtered": {
        "query": {
            "match_all": {}
        },
        "filter": {
            "bool": {
                "must": [{
                    "query": {
                        "match": {
                            "valid": "Y"
                        }
                    }
                }],
                "should": [
                    { "query": { "wildcard": { "name": { "value": '*' + searchValue + '*' } } } },
                    { "query": { "wildcard": { "fisrtname": { "value": '*' + searchValue + '*' } } } }   
                ]
            }
        }
    }
},
"sort": [{
    "name": {
        "order": "asec"
    }
}],
"from": 0,
"size": 15

Something like this:

{
  "query": {
    "bool": {
      "filter": {
        "bool": {
          "must": [
            {
              "match": {
                "valid": "Y"
              }
            }
          ],
          "should": [
            {
              "wildcard": {
                "name": {
                  "value": "searchValue"
                }
              }
            },
            {
              "wildcard": {
                "firstname": {
                  "value": "searchValue"
                }
              }
            }
          ]
        }
      }
    }
  },
  "sort": [
    {
      "name": {
        "order": "asc"
      }
    }
  ],
  "from": 0,
  "size": 15
}

The first bool.filter wrapper is so everything is treated as filter and not scored and possibly cached.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM