Don't found value by search request

Hi All,
I have a next search request:

GET /my_index/my_type/_search
{
  "query": {
    "bool": {
      "filter": [{
        "bool": {
          "should": [{
            "bool": {
              "must": [{
                "bool": {
                  "should": [
                    {"terms": {"siteid": ["1","16"]}},
                    {"prefix": {"firstname": {"value": "sergey"}}},
                    {"prefix": {"lastname": {"value": "sergey"}}}
                  ]
                }
              }],
              "should": [
                {"prefix": {"firstsecond": {"value": "sergey"}}},
                {"prefix": {"firstsecond": {"value": "pavlichenko"}}}
              ]
            }
          }]
        }
      }]
    }
  }
}

it doesn't find existing item, but when I execute next request:

GET /my_index/_search?q=id:178

I see that the item, is exist:

{
  "took": 1,
  "timed_out": false,
  "_shards": {
    "total": 5,
    "successful": 5,
    "failed": 0
  },
  "hits": {
    "total": 1,
    "max_score": 1.0,
    "hits": [{
        "_index": "dbcustomers3",
        "_type": "dbcustomers",
        "_id": "178",
        "_score": 1.0,
        "_source": {
          "id": 178,
          "updatedate": "2009-08-02T15:23:32.207",
          "email": "smaltsin222222@mail.comss",
          "merchantcustomeremail": null,
          "firstname": "maltsin123",
          "lastname": "sergey123",
          "login": "maltsin",
          "dateofbirth": "1971-01-01T00:00:00",
          "phone": "1234567890",
          "firstsecond": null,
          "md5password": null,
          "cardholders": "",
          "affmoenybookersemail": null,
          "moneybookerswithdrawemail": null,
          "siteid": 1,
          "lastloginip": "1.1.0.135"
        }
      }
    ]
  }
}

As I understood:

  1. it check for top should, and if one of cause (term or prefixes) correct, it proceed to must -> it means at list one of this should must be present
  2. then proceed bottom should and one of this cause (prefixes) also should be present
  3. covering by should give us ability to select at list one of 1st or 2nd case
  4. do filtering by this cause -> so we will get only items for which 1st or 2nd rule return true

Am I right?

This document does not match because one of the bottom should clauses is required to match. Yet the document has null as a value for firstsecond.

Ok, could you help then rewrite request from ES 2.0 to ES 5.5, because I'm in the middle of nowhere...

{
  "filter": {
    "bool": {
      "should": [
        {
          "bool": {
            "must": [
              {
                "bool": {
                  "should": [
                    {"term": {"siteid": "1"}},
                    {"term": {"siteid": "16"}}
                  ]
                }
              },
              {
                "bool": {
                  "should": [
                    {"prefix": {"firstname": {"prefix": "sergey"}}},
                    {"prefix": {"lastname": {"prefix": "sergey"}}}
                  ]
                }
              }
            ]
          }
        },
        {
          "bool": {
            "should": [
              {"prefix": {"firstsecond": {"prefix": "sergey"}}},
              {"prefix": {"firstsecond": {"prefix": "pavlichenko"}}}
            ]
          }
        }
      ]
    }
  }
}

Also I tried next variant, but unsuccessfully:

{
  "query": {
    "bool": {
      "filter": [{
          "bool": {
            "should": [
              {
                "bool": {
                  "must": [
                    {
                      "bool": {
                        "should": [
                          {"terms": {"siteid": ["1", "16"]}},
                          {"prefix": {"firstname": {"value": "sergey"}}},
                          {"prefix": {"lastname": {"value": "sergey"}}}
                        ]
                      }
                    }
                  ]
                }
              },
              {
                "bool": {
                  "should": [
                    {"prefix": {"firstsecond": {"value": "sergey"}}},
                    {"prefix": {"firstsecond": {"value": "pavlichenko"}}}
                  ]
                }
              }
            ]
          }
        }
      ]
    }
  }
}

Done, doesn't required answer, thanks

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.