# How does In\_order attribute affecting span near scoring

**URL:** <https://discuss.elastic.co/t/how-does-in-order-attribute-affecting-span-near-scoring/76531>\
**Category:** Elasticsearch\
**Created:** [February 26, 2017, 10:17am UTC](https://discuss.elastic.co/t/how-does-in-order-attribute-affecting-span-near-scoring/76531 "2017-02-26T10:17:51Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Johann\_Lutterodt](https://avatars.discourse-cdn.com/v4/letter/j/d26b3c/32.png) [@Johann\_Lutterodt](https://discuss.elastic.co/u/Johann_Lutterodt)\
**Post date:** [February 26, 2017, 10:17am UTC](https://discuss.elastic.co/t/how-does-in-order-attribute-affecting-span-near-scoring/76531/1 "2017-02-26T10:17:51Z")

</div>

From the sample doc and query below I seem to be getting different scores when I change the In\_order attribute. My question is why does the PhraseFreq change from 0.16666667 when In\_order is set to false to 0.25 when set to true.

From what I have gathered the PhraseFreq is calculated by 1/(dist+1).  
In both queries the dist would be 3 hence a PhraseFreq of 1/4 = 0.25. This explains the PhraseFreq when In\_order is set to true but not when it is set to false.

Example doc:

```
PUT testindex/type/1
{
	"text":"a b c d e f g h i"
}

```

Query With In\_order attribute set to false:

```
GET testindex/type/_search
{
  "explain": true, 
  "query": { 
    "span_near" : {
        "clauses" : [
            { "span_term" : { "text" : "a" } },
            { "span_term" : { "text" : "c" } },
            { "span_term" : { "text" : "f" } }         
        ],
        "slop" : 100,
        "in_order" : false,
        "collect_payloads" : false
    }}
}

```

RESULT:

```
{
  "took": 1,
  "timed_out": false,
  "_shards": {
    "total": 5,
    "successful": 5,
    "failed": 0
  },
  "hits": {
    "total": 1,
    "max_score": 0.11744264,
    "hits": [
      {
        "_shard": 3,
        "_node": "qGVR96XTSdORS8pnRjHr2g",
        "_index": "test",
        "_type": "type",
        "_id": "1",
        "_score": 0.11744264,
        "_source": {
          "text": "a b c d e f g h i"
        },
        "_explanation": {
          "value": 0.11744264,
          "description": "sum of:",
          "details": [
            {
              "value": 0.11744264,
              "description": "weight(spanNear([text:a, text:c, text:f], 100, false) in 0) [PerFieldSimilarity], result of:",
              "details": [
                {
                  "value": 0.11744264,
                  "description": "fieldWeight in 0, product of:",
                  "details": [
                    {
                      "value": 0.4082483,
                      "description": "tf(freq=0.16666667), with freq of:",
                      "details": [
                        {
                          "value": 0.16666667,
                          "description": "phraseFreq=0.16666667",
                          "details": []
                        }
                      ]
                    }
...                     

```

Query with In\_order attribute set to true:

```
GET testindex/type/_search
{
  "explain": true, 
  "query": { 
    "span_near" : {
        "clauses" : [
            { "span_term" : { "text" : "a" } },
            { "span_term" : { "text" : "c" } },
            { "span_term" : { "text" : "f" } }
        ],
        "slop" : 100,
        "in_order" : true,
        "collect_payloads" : false
    }}
}

```

RESULT:

```
{
  "took": 2,
  "timed_out": false,
  "_shards": {
    "total": 5,
    "successful": 5,
    "failed": 0
  },
  "hits": {
    "total": 1,
    "max_score": 0.14383726,
    "hits": [
      {
        "_shard": 3,
        "_node": "qGVR96XTSdORS8pnRjHr2g",
        "_index": "test",
        "_type": "type",
        "_id": "1",
        "_score": 0.14383726,
        "_source": {
          "text": "a b c d e f g h i"
        },
        "_explanation": {
          "value": 0.14383726,
          "description": "sum of:",
          "details": [
            {
              "value": 0.14383726,
              "description": "weight(spanNear([text:a, text:c, text:f], 100, true) in 0) [PerFieldSimilarity], result of:",
              "details": [
                {
                  "value": 0.14383726,
                  "description": "fieldWeight in 0, product of:",
                  "details": [
                    {
                      "value": 0.5,
                      "description": "tf(freq=0.25), with freq of:",
                      "details": [
                        {
                          "value": 0.25,
                          "description": "phraseFreq=0.25",
                          "details": []
                        }
                      ]
...
```

---

<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 26, 2017, 10:18am UTC](https://discuss.elastic.co/t/how-does-in-order-attribute-affecting-span-near-scoring/76531/2 "2017-03-26T10:18:01Z")

</div>

Closed on March 26, 2017, 10:18am UTC

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