AppSearch Wrong Results From Response

Hi everyone, I'm quite new to the Elasticsearch world. I managed to configure Elastic Search Stack to run on docker, version 7.6.0 . I use AppSearch and I'm facing a strange behavior when I receive results. I've some documents on the engine. When this query

   {
  "query": "bas",
  "page": {
    "current": 1,
    "size": 10
  },
  "result_fields": {
    "localita": {
      "raw": {},
      "snippet": {
        "size": 100,
        "fallback": true
      }
    },
    "associazione_sportiva_dilettantistica": {
      "raw": {},
      "snippet": {
        "size": 100,
        "fallback": true
      }
    },
    "tipo": {
      "raw": {},
      "snippet": {
        "size": 100,
        "fallback": true
      }
    },
    "ente_promozione_sportiva": {
      "raw": {},
      "snippet": {
        "size": 100,
        "fallback": true
      }
    },
    "cognome": {
      "raw": {},
      "snippet": {
        "size": 100,
        "fallback": true
      }
    },
    "corso": {
      "raw": {},
      "snippet": {
        "size": 100,
        "fallback": true
      }
    },
    "indirizzo": {
      "raw": {},
      "snippet": {
        "size": 100,
        "fallback": true
      }
    },
    "created_at": {
      "raw": {},
      "snippet": {
        "size": 100,
        "fallback": true
      }
    },
    "id": {
      "raw": {},
      "snippet": {
        "size": 100,
        "fallback": true
      }
    },
    "limite_partecipanti": {
      "raw": {},
      "snippet": {
        "size": 100,
        "fallback": true
      }
    },
    "provincia": {
      "raw": {},
      "snippet": {
        "size": 100,
        "fallback": true
      }
    },
    "regione": {
      "raw": {},
      "snippet": {
        "size": 100,
        "fallback": true
      }
    },
    "codice_fiscale": {
      "raw": {},
      "snippet": {
        "size": 100,
        "fallback": true
      }
    },
    "updated_at": {
      "raw": {},
      "snippet": {
        "size": 100,
        "fallback": true
      }
    },
    "comitato": {
      "raw": {},
      "snippet": {
        "size": 100,
        "fallback": true
      }
    },
    "host": {
      "raw": {},
      "snippet": {
        "size": 100,
        "fallback": true
      }
    },
    "max_partecipanti": {
      "raw": {},
      "snippet": {
        "size": 100,
        "fallback": true
      }
    },
    "descrizione_breve": {
      "raw": {},
      "snippet": {
        "size": 100,
        "fallback": true
      }
    },
    "fax": {
      "raw": {},
      "snippet": {
        "size": 100,
        "fallback": true
      }
    },
    "telefono": {
      "raw": {},
      "snippet": {
        "size": 100,
        "fallback": true
      }
    },
    "slug": {
      "raw": {},
      "snippet": {
        "size": 100,
        "fallback": true
      }
    },
    "email": {
      "raw": {},
      "snippet": {
        "size": 100,
        "fallback": true
      }
    },
    "partita_iva": {
      "raw": {},
      "snippet": {
        "size": 100,
        "fallback": true
      }
    },
    "citta": {
      "raw": {},
      "snippet": {
        "size": 100,
        "fallback": true
      }
    },
    "nome_abbreviato": {
      "raw": {},
      "snippet": {
        "size": 100,
        "fallback": true
      }
    },
    "manager": {
      "raw": {},
      "snippet": {
        "size": 100,
        "fallback": true
      }
    },
    "internal_id": {
      "raw": {},
      "snippet": {
        "size": 100,
        "fallback": true
      }
    },
    "socio": {
      "raw": {},
      "snippet": {
        "size": 100,
        "fallback": true
      }
    },
    "costo": {
      "raw": {},
      "snippet": {
        "size": 100,
        "fallback": true
      }
    },
    "min_partecipanti": {
      "raw": {},
      "snippet": {
        "size": 100,
        "fallback": true
      }
    },
    "durata": {
      "raw": {},
      "snippet": {
        "size": 100,
        "fallback": true
      }
    },
    "nome": {
      "raw": {},
      "snippet": {
        "size": 100,
        "fallback": true
      }
    },
    "message": {
      "raw": {},
      "snippet": {
        "size": 100,
        "fallback": true
      }
    },
    "tags": {
      "raw": {},
      "snippet": {
        "size": 100,
        "fallback": true
      }
    },
    "durata_attivita": {
      "raw": {},
      "snippet": {
        "size": 100,
        "fallback": true
      }
    },
    "descrizione": {
      "raw": {},
      "snippet": {
        "size": 100,
        "fallback": true
      }
    },
    "port": {
      "raw": {},
      "snippet": {
        "size": 100,
        "fallback": true
      }
    },
    "sito_web": {
      "raw": {},
      "snippet": {
        "size": 100,
        "fallback": true
      }
    },
    "immagine": {
      "raw": {},
      "snippet": {
        "size": 100,
        "fallback": true
      }
    },
    "manager_asd": {
      "raw": {},
      "snippet": {
        "size": 100,
        "fallback": true
      }
    },
    "user": {
      "raw": {},
      "snippet": {
        "size": 100,
        "fallback": true
      }
    },
    "username": {
      "raw": {},
      "snippet": {
        "size": 100,
        "fallback": true
      }
    }
  }
}

I receive just 1 result (as I expect), but when i try to add a letter into the query I received 3 results but two of them doesn't have anything that is in the query field.
Am I doing something wrong?

Thanks in advance to everyone.

EDIT

I've tested this also on a new engine with 1 document only, for this test I've used version 7.8.0 of Elasticsearch and moved everything under Enterprise Search. I've used this document for the test

{
  "tipo": "corso",
  "internal_id": 2,
  "nome": "Corso Windsurf",
  "durata": "1 mese",
  "descrizione": "Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam eaque ipsa, quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt, explicabo. Nemo enim ipsam voluptatem, quia voluptas sit, aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos, qui ratione voluptatem sequi nesciunt, neque porro quisquam est, qui dolorem ipsum, quia dolor sit, amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt, ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit, qui in ea voluptate velit esse, quam nihil molestiae consequatur, vel illum, qui dolorem eum fugiat, quo voluptas nulla pariatur?  At vero eos et accusamus et iusto odio dignissimos ducimus, qui blanditiis praesentium voluptatum deleniti atque corrupti, quos dolores et quas molestias excepturi sint, obcaecati cupiditate non provident, similique sunt in culpa, qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio, cumque nihil impedit, quo minus id, quod maxime placeat, facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Temporibus autem quibusdam et aut officiis debitis aut rerum necessitatibus saepe eveniet, ut et voluptates repudiandae sint et molestiae non recusandae. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.",
  "descrizione_breve": "Corso Windsurf",
  "regione": "Puglia",
  "provincia": "Lecce",
  "citta": "Lecce",
  "slug": "corso-windsurf",
  "costo": "100",
  "max_partecipanti": null,
  "associazione_sportiva_dilettantistica": "1",
  "immagine": "/uploads/windsurf_a8896e8fb7.jpeg",
  "tags": [
    "Mare",
    "windsurf"
  ],
  "id": "corso_2"
}

With query tester I searched for "bas", and as I expected I received 0 results
then I tested again with this word "basi", but in this case i received 1 result.
Then I removed the document from engine and re-added it but without the "descrizione" field.
I re-launched query tester with both the previous queries and in both response I received 0 results.
So I'm wondering if the problem is a long text in the document that could cause this strange behaviour.

So you seeing results that you don't believe should match your query?

App Search favors recall over precision in queries. In other words, we do very aggressive matching which results in a large result set, but we have an advanced relevance system that ensures that the most relevant results are always shown first.

It's totally normal to see documents in your results where it's not immediately apparent why it's a match.

Yeah exactly.

It's totally normal to see documents in your results where it's not immediately apparent why it's a match.

The fact is the there's nothing that should match that query. Considering your answer, I still can't understand why with this query "bas" i have 1 result and with this query "basi" I get 3 results. If it's all about relevance I should have 3 results also in first case? Is my thinking right?

BTW I also tried reducing the size of the field "descrizione" to 500 chars. With resizing, results returns as I expected.

The fact is the there's nothing that should match that query.

The value of "descrizione" is as follows.

Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam eaque ipsa, quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt, explicabo. Nemo enim ipsam voluptatem, quia voluptas sit, aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos, qui ratione voluptatem sequi nesciunt, neque porro quisquam est, qui dolorem ipsum, quia dolor sit, amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt, ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit, qui in ea voluptate velit esse, quam nihil molestiae consequatur, vel illum, qui dolorem eum fugiat, quo voluptas nulla pariatur? At vero eos et accusamus et iusto odio dignissimos ducimus, qui blanditiis praesentium voluptatum deleniti atque corrupti, quos dolores et quas molestias excepturi sint, obcaecati cupiditate non provident, similique sunt in culpa, qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio, cumque nihil impedit, quo minus id, quod maxime placeat, facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Temporibus autem quibusdam et aut officiis debitis aut rerum necessitatibus saepe eveniet, ut et voluptates repudiandae sint et molestiae non recusandae. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.

If you are searching for the text "basi", "basi" is compared against each word in that field individually looking for a match. There is a high likelyhood that in a field with that many words that one of them will match. Remember, it's a very aggressive search, so it doesn't have to be an exact match, it could be a "fuzzy" match where 3 of the 4 characters match, for instance.

If you don't want to match on the "descrizione" field, you can change which fields are searchable in the "Relevance Tuning" section of the Dashboard, or programatically in your search calls Search API search fields | App Search documentation [8.11] | Elastic

Nope, that's not how it works. There's certain types of matching that may not be enabled unless you're searching for a minimum number of characters, for instance. Like prefix matching. If we tried to do prefix matching when all you've searched for is "b", you will get way too many results.

Ok thanks for your explanation. Now it's more clear. I guess I'll try with the "relevance tuning" approach.
Again, thanks

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