# What index(actual lucene inverted index) does a query request hit?

**URL:** <https://discuss.elastic.co/t/what-index-actual-lucene-inverted-index-does-a-query-request-hit/220072>\
**Category:** Elasticsearch\
**Created:** [February 20, 2020, 2:59am UTC](https://discuss.elastic.co/t/what-index-actual-lucene-inverted-index-does-a-query-request-hit/220072 "2020-02-20T02:59:39Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![addhawan](https://avatars.discourse-cdn.com/v4/letter/a/58f4c7/32.png) [@addhawan](https://discuss.elastic.co/u/addhawan)\
**Post date:** [February 20, 2020, 2:59am UTC](https://discuss.elastic.co/t/what-index-actual-lucene-inverted-index-does-a-query-request-hit/220072/1 "2020-02-20T02:59:39Z")

</div>

Hi,  
I want to understand how a query is executed and what all lucene indexes does it hit to find a match?

Lets say I have a document like:

```auto
{
	"id":"id_1",
	"fName":"John",
	"lName":"DOe",
	"age":28,
	"email":"johndoe@exmple.com",
	"aboutMe":"A fictitious name used to identify an unknown man or body. Also referred to as 'Jane Doe'."
}

```

an index mapping like:

```auto
"person-index": {
    "mappings": {
      "person": {
        "dynamic": "false",
        "properties": {
        	"id": {
            "type": "keyword"
            },
            "fName": {
            "type": "keyword"
            },
            "lName": {
            "type": "keyword"
            },
            "age": {
            "type": "long"
            },
            "email": {
            "type": "keyword"
            },
            "aboutMe": {
            "type": "text"
            }
        }
      }
    }
}

```

My query is like:

1. Query1:

```auto
{
  "query": {
    "bool": {
      "filter": [
        {
          "bool": {
            "filter": [
              {
                "term": {
                  "id": {
                    "value": "id1"
                  }
                }
              }
            ]
          }
        },
        {
          "bool": {
            "filter": [
              {
                "term": {
                  "fName": {
                    "value": "John"
                  }
                }
              }
            ]
          }
        }
      ]
    }
  }
}

```

1. Query2:

```auto
{
  "query": {
    "bool": {
      "filter": [
        {
          "bool": {
            "filter": [
              {
                "term": {
                  "id": {
                    "value": "id1"
                  }
                }
              }
            ]
          }
        },
        {
          "bool": {
            "match": [
              {
                "aboutMe": {
                  "query": "unknown"
                }
              }
            ]
          }
        }
      ]
    }
  }
}

```

1. While indexing, what all inverted indexes are created?
2. Does ES create inverted indexes for a `keyword` type mapping fields?
3. When the query is passed to a particular shard, which inverted indexes are hit?  
3.1 Are all of the (lucene)indexes in query hit?  
3.2 How does elasticsearch decide in what order are these indexes hit?
4. If looking at similar document indexing in a Document database like MongoDb, we would end up creating a specific index. What kind of algorithm do databases like mongoDB in general use to select a particular index to fulfill a query
5. How is the algorithm in case of elasticsearch to find a index to hit different in case of elastic-search than other databases, say MongoDb?

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:** [March 19, 2020, 2:59am UTC](https://discuss.elastic.co/t/what-index-actual-lucene-inverted-index-does-a-query-request-hit/220072/2 "2020-03-19T02:59:44Z")

</div>

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