0

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

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

请帮我!我真的在尽我所能在谷歌上找到的东西。也许有人知道是什么问题。

索引映射:

    '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'
                ],
            ]
        ]
    ]
];

索引中的文档:

 {
    "_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"
          }
        }
      }
    }
  },

错误:

    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}

我的查询:

            'index' => StopWord::STOP_WORDS_ELASTICSEARCH_INDEX_NAME,
            '_source' => ['id'],
            'body' => [
                'query' => [
                    'bool' => [
                        'filter' => [
                            ['term' => ['status' => true]],
                            ['percolate' => [
                                'field' => 'stop_query',
                                'documents' => $fields
                            ]]
                        ]
                    ]
                ]
            ]
4

1 回答 1

1

问题出在索引映射中。我有不同的功能来创建索引。其中一个功能是使用带有映射的索引模板,另一个不是。所以我在没有映射的情况下创建索引的功能有问题。比我在索引中插入文档,ES 创建他自己的必须渗透的字段映射。

这就是为什么我在尝试使用字段作为渗透时出错的原因。

于 2022-01-31T11:38:43.767 回答