首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >为什么我有一个ElasticSearch渗滤查询错误?

为什么我有一个ElasticSearch渗滤查询错误?
EN

Stack Overflow用户
提问于 2022-01-06 13:20:09
回答 1查看 144关注 0票数 0

当我在ElasticSearch中创建索引并试图使用percolate时,出现了一个错误,即索引中不存在带percolate类型的字段。但是当我在索引中观看时,字段是存在的。

我将向您展示映射,文档在索引、错误和查询中的样子。

请帮帮我!我真的在尽我所能在谷歌上找到一切。也许有人知道问题出在哪里。

索引映射:

代码语言:javascript
复制
    'index' => 'stop-words',
    'body' => [
        'settings' => [
            'number_of_shards' => 3,
            'number_of_replicas' => 2,
            'analysis' => [
                'analyzer' => [
                    'simple_punctuation_analyzer' => [
                        'type' => 'custom',
                        'tokenizer' => 'simple_punctuation_tokenizer',
                        'char_filter' => ['html_strip'],
                        'filter' => ['lowercase']
                    ]
                ],
                'tokenizer' => [
                    'simple_punctuation_tokenizer' => [
                        'type' => 'char_group',
                        'tokenize_on_chars' => [
                            'whitespace',
                            ',',
                            '.',
                            '\'',
                            '"',
                            ':',
                            ';',
                            '?',
                            '!'
                        ]
                    ]
                ]
            ]
        ],
        'mappings' => [
            'properties' => [
                'id' => [
                    'type' => 'long'
                ],
                'stop_word' => [
                    'type' => 'text',
                    'analyzer' => 'simple_punctuation_analyzer',
                    'fields' => [
                        'keyword' => [
                            'type' => 'keyword'
                        ]
                    ]
                ],
                'stop_query' => [
                    'type' => 'percolator'
                ],

                'status' => [
                    'type' => 'boolean'
                ],
            ]
        ]
    ]
];

Doc索引:

代码语言:javascript
复制
 {
    "_index": "stop-words",
    "_type": "_doc",
    "_id": "1",
    "_score": 1.0,
    "_source": {
      "id": 1,
      "stop_word": "asdasdasd",
      "stop_query": {
        "match_phrase": {
          "stop_word": {
            "query": "asdasdasd",
            "analyzer": "simple_punctuation_analyzer"
          }
        }
      }
    }
  },

错误:

代码语言:javascript
复制
    Error: {"error":{"root_cause":
            [{"type":"query_shard_exception",
              "reason":"field [stop_query] does not exist",
              "index_uuid":"I9ZjvdjCQuyHylKTDicRRg",
              "index":"stop-words"}],
              "type":"search_phase_execution_exception",
              "reason":"all shards failed",
              "phase":"query",
              "grouped":true,
              "failed_shards":[{"shard":0,"index":"stop-words",
                                "node":"PqSzl30DRnaNkFyp8RkOxg",
                                "reason":
                                   {"type":"query_shard_exception",
                                    "reason":"field [stop_query] does not exist",
                                    "index_uuid":"I9ZjvdjCQuyHylKTDicRRg",
                                    "index":"stop-words"}}]},"status":400}

我的问题是:

代码语言:javascript
复制
            'index' => StopWord::STOP_WORDS_ELASTICSEARCH_INDEX_NAME,
            '_source' => ['id'],
            'body' => [
                'query' => [
                    'bool' => [
                        'filter' => [
                            ['term' => ['status' => true]],
                            ['percolate' => [
                                'field' => 'stop_query',
                                'documents' => $fields
                            ]]
                        ]
                    ]
                ]
            ]
EN

回答 1

Stack Overflow用户

发布于 2022-01-31 11:38:43

问题在于索引映射。对于创建索引,我有不同的功能。其中一个函数是使用带映射的索引模板,另一个则不是。因此,我在创建索引而不进行映射的函数上遇到了问题。而不是我在索引中插入文档,ES创建了他自己的字段映射,该字段必须是渗流的。

这就是为什么我试图使用一个字段作为渗滤液时出错的原因。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/70607736

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档