Elasticsearch - similary for countries

2019-08-09 03:18发布

问题:

I have a document, which contains many fields, one of them is country. There are many documents with the same country.

When I do match query, or fuzzy search against country, and query for Belgium for example, it returns list of documents, which matched Belgium country, but they all have different score. I believe it's because of tdidf similarity and presence of belgium term in other fields of documents, etc.

I'd like it return the same score in this case. What similarity should I use?

Update

I have next 6 documents:

{country:"Austria", title: "house"}
{country:"Austria", title: "Austria village"}
{country: "Germany", title: "deutch hotel" }
{country:"Austria", title: ""}
{country: "USA", title: "Usa hotel" }
{country: "USA", title: "Usa another hotel" }

When I execute match query against country:

{
   query: {match: {country: "Austria"}}
}

I reveice next results:

[ {
  "_index" : "elasticdemo_docs",
  "_type" : "doc",
  "_id" : "1",
  "_score" : 1.0, "_source" : {country:"Austria", title: "Austria village"}
}, {
  "_index" : "elasticdemo_docs",
  "_type" : "doc",
  "_id" : "2",
  "_score" : 0.30685282, "_source" : {country:"Austria", title: "house"}
}, {
  "_index" : "elasticdemo_docs",
  "_type" : "doc",
  "_id" : "3",
  "_score" : 0.30685282, "_source" : {country:"Austria", title: ""}
} ]

I'd like to receive the same _score for all 3 documents, because they all have Austria as a country. What similarity should I use?

回答1:

Seems I found the problem - it's connected with: http://www.elasticsearch.org/blog/understanding-query-then-fetch-vs-dfs-query-then-fetch/

After using dfs_query_then_fetch search type I've got expected results.