elasticsearch - Elasticsearch Facet token 化

标签 elasticsearch tokenize

我正在使用terms facet在elasticsearch服务器中获取顶级terms。现在,我的标签"indian-government"不被视为一个标签。将其视为"indian" "government"。因此,最常用的标签是"indian"如何解决此问题?我应该更改 token 化吗?

        'settings': {
                'analysis': {
                        'analyzer': {
                                'my_ngram_analyzer' : {
                                        'tokenizer' : 'my_ngram_tokenizer',
                                         'filter': ['my_synonym_filter']
                                 }
                        },
                         'filter': {
                                 'my_synonym_filter': {
                                        'type': 'synonym',
                                        'format': 'wordnet',
                                        'synonyms_path': 'analysis/wn_s.pl'
                                }
                        },
                         'tokenizer' : {
                                 'my_ngram_tokenizer' : {
                                        'type' : 'nGram',
                                        'min_gram' : '1',
                                        'max_gram' : '50'
                                }
                        }
                }
        }

编辑:基于注释,索引如下。结果不会改变:
    es.indices.create(
            index="article-index",
            body={
                    'settings': {
                            'analysis': {
                                    'analyzer': {
                                            'my_ngram_analyzer' : {
                                                    'tokenizer' : 'my_ngram_tokenizer',
                                                    'filter': ['my_synonym_filter']
                                            }
                                    },
                                    'filter': {
                                            'my_synonym_filter': {
                                                    'type': 'synonym',
                                                    'format': 'wordnet',
                                                    'synonyms_path': 'analysis/wn_s.pl'
                                            }
                                    },
                                    'tokenizer' : {
                                            'my_ngram_tokenizer' : {
                                                    'type' : 'nGram',
                                                    'min_gram' : '1',
                                                    'max_gram' : '50'
                                            }
                                    }
                            }
                    },
                       'mappings': {
                            'my_mapping_type': {
                                  '_all': {
                                    'enabled': False
                                  },
                                  '_source': {
                                    'compressed': True
                                  },
                                  'properties': {
                                    "tags": {
                                      "type": "string",
                                      "index": "not_analyzed"
                                    }
                                  }
                            }
                    }
            },
            # ignore already existing index
            ignore=400
    )

编辑:解决。 my_mapping_type必须替换为doc_type(在我的情况下是其“文章”),并且可以正常工作:)

最佳答案

如果需要,将字段 not_analysed 设为should work

curl -XPUT localhost:9200/INDEX -d '{
  "settings": {
    "number_of_shards": 5,
    "number_of_replicas": 2
  },
  "mappings": {
    "my_type": {
      "_all": {
        "enabled": false
      },
      "_source": {
        "compressed": true
      },
      "properties": {
        "tag": {
          "type": "string",
          "index": "not_analyzed"
        }
      }
    }
  }
}'

关于elasticsearch - Elasticsearch Facet token 化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23711001/

相关文章:

docker - 使用 elasticsearch 图像运行 docker-compose up 时抛出 Java 错误

elasticsearch - ElasticSearch gem方法可扫描索引中的所有文档

Python 标记化

token - 聊天GPT : How to use long texts of unknown content in a prompt?

java - JAVA无法读取字符串结尾

elasticsearch - Elasticsearch生成建议字段

java - Storm Crawler中ES查询异常

java - 带有 LookAhead 的 Lucene 分词器

php - 将每个文本文件的内容保存到数据库表 mysql 中

elasticsearch - 标点不正确的结果-ElasticSearch