Elasticsearch: Comportement étrange de recherche lors de l'utilisation de Snowball Analyzer

StackOverflow https://stackoverflow.com//questions/9700962

  •  13-12-2019
  •  | 
  •  

Question

Alors disons que j'ai un indice élasticsearch défini comme celui-ci:

curl -XPUT 'http://localhost:9200/test' -d '{
  "mappings": {
    "example": {
      "properties": {
        "text": {
          "type": "string",
          "analyzer": "snowball"
        }
      }
    }
  }
}'

curl -XPUT 'http://localhost:9200/test/example/1' -d '{
  "text": "foo bar organization"
}'

Lorsque je recherche "FOO Organisations" avec Analyseur de Snowball, les deux mots-clés correspondent comme prévu:

curl -XGET http://localhost:9200/test/example/_search -d '{
  "query": {
    "text": {
      "_all": {
        "query": "foo organizations",
        "analyzer": "snowball"
      }
    }
  },
  "highlight": {
    "fields": {
      "text": {}
    }
  }
}'

{
  "took": 1,
  "timed_out": false,
  "_shards": {
    "total": 5,
    "successful": 5,
    "failed": 0
  },
  "hits": {
    "total": 1,
    "max_score": 0.015912745,
    "hits": [
      {
        "_index": "test",
        "_type": "example",
        "_id": "1",
        "_score": 0.015912745,
        "_source": {
          "text": "foo bar organization"
        },
        "highlight": {
          "text": [
            "<em>foo</em> bar <em>organization</em>"
          ]
        }
      }
    ]
  }
}

Mais lorsque je ne cherche que des "organisations", je ne reçois aucun résultat du tout, ce qui est très bizarre:

curl -XGET http://localhost:9200/test/example/_search -d '{
  "query": {
    "text": {
      "_all": {
        "query": "organizations",
        "analyzer": "snowball"
      }
    }
  },
  "highlight": {
    "fields": {
      "text": {}
    }
  }
}'

{
  "took": 1,
  "timed_out": false,
  "_shards": {
    "total": 5,
    "successful": 5,
    "failed": 0
  },
  "hits": {
    "total": 0,
    "max_score": null,
    "hits": []
  }
}

Cependant, si je recherche "bars", il frappe toujours:

curl -XGET http://localhost:9200/test/example/_search -d '{
  "query": {
    "text": {
      "_all": {
        "query": "bars",
        "analyzer": "snowball"
      }
    }
  },
  "highlight": {
    "fields": {
      "text": {}
    }
  }
}'

{
  "took": 1,
  "timed_out": false,
  "_shards": {
    "total": 5,
    "successful": 5,
    "failed": 0
  },
  "hits": {
    "total": 1,
    "max_score": 0.10848885,
    "hits": [
      {
        "_index": "test",
        "_type": "example",
        "_id": "1",
        "_score": 0.10848885,
        "_source": {
          "text": "foo bar organization"
        },
        "highlight": {
          "text": [
            "foo <em>bar</em> organization"
          ]
        }
      }
    ]
  }
}

Je suppose que la différence entre "bar" et "organisation" est que "l'organisation" est titée à "organe" pendant que "bar" est tirée à elle-même.Mais comment puis-je obtenir le comportement approprié pour que la deuxième recherche frappe?

Était-ce utile?

La solution

Texte "FOO BAR ORGANISATION" devient indexé deux fois - sur le terrain texte et sur le terrain _all .Le champ texte utilise l'analyseur de boulets de neige et le champ _All utilise analyseur standard.Par conséquent, après analyse de l'enregistrement de test, le champ _all contient des jetons: "foo", "bar" et "organisation".Pendant la recherche, l'analyseur de boule de neige spécifié convertit "FOO" dans "FOO", "BARS" dans "BAR" ET "Organisation" dans "Organe".Ainsi, les mots "foo" et "barres" dans la requête correspondent à l'enregistrement de test et au terme "organisation" ne le font pas.La surbrillance est effectuée sur la base de champ de manière indépendante de la recherche et c'est pourquoi le mot "organisation" est mis en évidence dans le premier résultat.

Autres conseils

Il est préférable d'utiliser Analyzer à l'heure de l'index que de l'heure de la recherche..map votre champ de texte à l'analyseur de la balle à neige puis de l'index.Cela créera des jetons pour une organisation qui inclut des organisations.Il fonctionne pour moi

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top