# Don't found value by search request

**URL:** <https://discuss.elastic.co/t/dont-found-value-by-search-request/96124>\
**Category:** Elasticsearch\
**Created:** [August 7, 2017, 2:24pm UTC](https://discuss.elastic.co/t/dont-found-value-by-search-request/96124 "2017-08-07T14:24:12Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![denis.peshkov](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/denis.peshkov/32/20686_2.png) [@denis.peshkov](https://discuss.elastic.co/u/denis.peshkov)\
**Post date:** [August 7, 2017, 2:24pm UTC](https://discuss.elastic.co/t/dont-found-value-by-search-request/96124/1 "2017-08-07T14:24:12Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![denis.peshkov](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/denis.peshkov/32/20686_2.png) [@denis.peshkov](https://discuss.elastic.co/u/denis.peshkov)\
**Post date:** [August 7, 2017, 2:32pm UTC](https://discuss.elastic.co/t/dont-found-value-by-search-request/96124/2 "2017-08-07T14:32:11Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![jpountz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jpountz/32/45836_2.png) [@jpountz](https://discuss.elastic.co/u/jpountz)\
**Post date:** [August 7, 2017, 5:02pm UTC](https://discuss.elastic.co/t/dont-found-value-by-search-request/96124/3 "2017-08-07T17:02:28Z")

</div>

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`.

---

<div class="post-metadata">

**Author:** ![denis.peshkov](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/denis.peshkov/32/20686_2.png) [@denis.peshkov](https://discuss.elastic.co/u/denis.peshkov)\
**Post date:** [August 8, 2017, 7:50am UTC](https://discuss.elastic.co/t/dont-found-value-by-search-request/96124/4 "2017-08-08T07:50:26Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![denis.peshkov](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/denis.peshkov/32/20686_2.png) [@denis.peshkov](https://discuss.elastic.co/u/denis.peshkov)\
**Post date:** [August 8, 2017, 8:27am UTC](https://discuss.elastic.co/t/dont-found-value-by-search-request/96124/5 "2017-08-08T08:27:48Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![denis.peshkov](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/denis.peshkov/32/20686_2.png) [@denis.peshkov](https://discuss.elastic.co/u/denis.peshkov)\
**Post date:** [August 8, 2017, 10:11am UTC](https://discuss.elastic.co/t/dont-found-value-by-search-request/96124/6 "2017-08-08T10:11:10Z")

</div>

Done, doesn't required answer, thanks

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [September 5, 2017, 10:11am UTC](https://discuss.elastic.co/t/dont-found-value-by-search-request/96124/7 "2017-09-05T10:11:23Z")

</div>

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