# Indices\_boost not work for has\_child query

**URL:** <https://discuss.elastic.co/t/indices-boost-not-work-for-has-child-query/328566>\
**Category:** Elasticsearch\
**Created:** [March 26, 2023, 7:57pm UTC](https://discuss.elastic.co/t/indices-boost-not-work-for-has-child-query/328566 "2023-03-26T19:57:33Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tiago1515](https://avatars.discourse-cdn.com/v4/letter/t/a87d85/32.png) [@Tiago1515](https://discuss.elastic.co/u/Tiago1515)\
**Post date:** [March 26, 2023, 7:57pm UTC](https://discuss.elastic.co/t/indices-boost-not-work-for-has-child-query/328566/1 "2023-03-26T19:57:33Z")

</div>

# Context

- Elasticsearch version: 8.8.0-SNAPSHOT (Commit: 56633e0a2934b03090ab726c33e5289129c98bfe [56633e0])
- Lucene version: lucene-join-9.6.0-SNAPSHOT

I create two equals indices:

```json
PUT /question_answer_1
{
  "aliases": {
    "question_answer": {}
  },
  "settings": {
    "number_of_shards": 1,
    "number_of_replicas": 0
  },
  "mappings": {
    "properties": {
      "text": { "type": "text" },
      "join": {
        "type": "join",
        "relations": {
          "question": "answer" 
        }
      }
    }
  }
}

```

```json
PUT /question_answer_2
{
  "aliases": {
    "question_answer": {}
  },
  "settings": {
    "number_of_shards": 1,
    "number_of_replicas": 0
  },
  "mappings": {
    "properties": {
      "text": { "type": "text" },
      "join": {
        "type": "join",
        "relations": {
          "question": "answer" 
        }
      }
    }
  }
}

```

So, i populated with following data:

```json
PUT question_answer_1/_doc/1?refresh
{
  "text": "what is the first question?",
  "join": { "name": "question" }
}

PUT question_answer_1/_doc/1-1?routing=1&refresh
{
  "text": "this is the first response of the first question",
  "join": { "name": "answer", "parent": "1" }
}

PUT question_answer_1/_doc/1-2?routing=1&refresh
{
  "text": "this is the second response of the first question",
  "join": { "name": "answer", "parent": "1" }
}

```

```json
PUT question_answer_2/_doc/1?refresh
{
  "text": "what is the first question?",
  "join": { "name": "question" }
}

PUT question_answer_2/_doc/1-1?routing=1&refresh
{
  "text": "this is the first response of the first question",
  "join": { "name": "answer", "parent": "1" }
}

PUT question_answer_2/_doc/1-2?routing=1&refresh
{
  "text": "this is the second response of the first question",
  "join": { "name": "answer", "parent": "1" }
}

```

# Problem

When i make this query:

```json
GET question_answer/_search
{
  "_source": false,
  "query": {
    "has_child": {
      "type": "answer",
      "score_mode": "max", 
      "query": {
        "match": {
          "text": "second"
        }
      }
    }
  }
}

```

the return is:

```json
{
    "took": 44,
    "timed_out": false,
    "_shards": {
        "total": 2,
        "successful": 2,
        "skipped": 0,
        "failed": 0
    },
    "hits": {
        "total": {
            "value": 2,
            "relation": "eq"
        },
        "max_score": 0.91568196,
        "hits": [
            {
                "_index": "question_answer_1",
                "_id": "1",
                "_score": 0.91568196
            },
            {
                "_index": "question_answer_2",
                "_id": "1",
                "_score": 0.91568196
            }
        ]
    }
}

```

If i use `indices_boost` to prioritize the index `question_answer_1` as following:

```json
GET question_answer/_search
{
  "indices_boost": [
    {
      "question_answer_1": 10
    }
  ],
  "_source": false,
  "query": {
    "has_child": {
      "type": "answer",
      "score_mode": "max", 
      "query": {
        "match": {
          "text": "second"
        }
      }
    }
  }
}

```

I expected that the document of `_id=1` and `_index=question_answer_1` return `_score=9.1568196` (10 \* 0.91568196), but the result is the same as before:

```json
{
    "took": 8,
    "timed_out": false,
    "_shards": {
        "total": 2,
        "successful": 2,
        "skipped": 0,
        "failed": 0
    },
    "hits": {
        "total": {
            "value": 2,
            "relation": "eq"
        },
        "max_score": 0.91568196,
        "hits": [
            {
                "_index": "question_answer_1",
                "_id": "1",
                "_score": 0.91568196
            },
            {
                "_index": "question_answer_2",
                "_id": "1",
                "_score": 0.91568196
            }
        ]
    }
}

```

Then i clonclude that the `indices_boost` does not work for `has_child` query. **Is it right?**

Debuging the Elasticsearch, i saw the following [code](https://github.com/apache/lucene/blob/0782535017c9e737350e96fb0f53457c7b8ecf03/lucene/join/src/java/org/apache/lucene/search/join/GlobalOrdinalsWithScoreQuery.java#L118-L120) in the GlobalOrdinalsWithScoreQuery Lucene class:

```java
    return new W(
        this,
        toQuery.createWeight(searcher, org.apache.lucene.search.ScoreMode.COMPLETE_NO_SCORES, 1f));

```

I change to

```java
    return new W(
        this,
        toQuery.createWeight(searcher, scoreMode, boost));

```

but does not work.

The `toString` method of class GlobalOrdinalsWithScoreQuery shows the following string:  
`(GlobalOrdinalsQuery{joinField=join#questionmin=1max=2147483647fromQuery=+text:second #join:answer})^10.0`

---

<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:** [April 23, 2023, 7:57pm UTC](https://discuss.elastic.co/t/indices-boost-not-work-for-has-child-query/328566/2 "2023-04-23T19:57:59Z")

</div>

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