2017-07-22 2 views
0

J'ai créé un index avec ngram analyseur défini sur tous les champs de l'index et _all personnalisé. Après l'indexation de quelques documents, j'essaie d'interroger l'index pour avoir une suggestion comme caractéristique.ElasticSearch Mise en surbrillance échoue sur les requêtes de correspondance avec l'index avec Ngram Analyzer

La sortie de la requête renvoie des résultats mais ils ne sont pas mis en surbrillance.

Réglages: Analyseur

"analysis": { 
    "analyzer": { 
    "my_edgegram_analyzer": { 
     "filter": [ 
     "lowercase" 
     ], 
     "tokenizer": "my_edge_tokenizer" 
    } 
    }, 
    "tokenizer": { 
    "my_edge_tokenizer": { 
     "token_chars": [ 
     "letter", 
     "digit", 
     "punctuation", 
     "symbol" 
     ], 
     "min_gram": "3", 
     "type": "ngram", 
     "max_gram": "26" 
    } 
    } 
} 

Cartographie:

{ 
    "st1": { 
    "mappings": { 
     "a": { 
     "_all": { 
      "enabled": false 
     }, 
     "dynamic_templates": [ 
      { 
      "catch_all": { 
       "match": "imp*", 
       "match_mapping_type": "string", 
       "mapping": { 
       "analyzer": "my_edgegram_analyzer", 
       "copy_to": "catch_all", 
       "norms": false, 
       "type": "text" 
       } 
      } 
      } 
     ], 
     "properties": { 
      "catch_all": { 
      "type": "text", 
      "store": true, 
      "analyzer": "my_edgegram_analyzer" 
      }, 
      "imp_server_id": { 
      "type": "text", 
      "norms": false, 
      "copy_to": [ 
       "catch_all" 
      ], 
      "analyzer": "my_edgegram_analyzer" 
      }, 
      "imp_server_name": { 
      "type": "text", 
      "norms": false, 
      "copy_to": [ 
       "catch_all" 
      ], 
      "analyzer": "my_edgegram_analyzer" 
      } 
     } 
     }, 
     "b": { 
     "_all": { 
      "enabled": false 
     }, 
     "dynamic_templates": [ 
      { 
      "catch_all": { 
       "match": "imp*", 
       "match_mapping_type": "string", 
       "mapping": { 
       "analyzer": "my_edgegram_analyzer", 
       "copy_to": "catch_all", 
       "norms": false, 
       "type": "text" 
       } 
      } 
      } 
     ], 
     "properties": { 
      "catch_all": { 
      "type": "text", 
      "store": true, 
      "analyzer": "my_edgegram_analyzer" 
      }, 
      "imp_server_id": { 
      "type": "text", 
      "norms": false, 
      "copy_to": [ 
       "catch_all" 
      ], 
      "analyzer": "my_edgegram_analyzer" 
      }, 
      "imp_server_name": { 
      "type": "text", 
      "norms": false, 
      "copy_to": [ 
       "catch_all" 
      ], 
      "analyzer": "my_edgegram_analyzer" 
      } 
     } 
     } 
    } 
    } 
} 

Documents:

http://localhost:9200/st1/b/1 

{"imp_server_name":"abc1-4-jam9.my.test.com","imp_server_id":"vrock2-us"} 

http://localhost:9200/st1/a/1 

{"imp_server_name":"abc2-5-ajm9.my.test.com","imp_server_id":"vrock2-us"} 

Requête:

{ 
    "query": { 
     "match": { 
      "catch_all": { 
      "query":"test", 
      "analyzer": "keyword" 
      } 
     } 

    }, 
"highlight": { 
     "pre_tags": ["<b>"], 
     "post_tags": ["</b>"], 
    "fields": { 
     "*": {} 
    }, 
    "require_field_match": false 
} 
} 

Réponse:

{ 
    "took": 3, 
    "timed_out": false, 
    "_shards": { 
    "total": 5, 
    "successful": 5, 
    "failed": 0 
    }, 
    "hits": { 
    "total": 2, 
    "max_score": 0.16292635, 
    "hits": [ 
     { 
     "_index": "st1", 
     "_type": "a", 
     "_id": "1", 
     "_score": 0.16292635, 
     "_source": { 
      "imp_server_name": "abc2-5-ajm9.my.test.com", 
      "imp_server_id": "vrock2-us" 
     }, 
     "highlight": { 
      "imp_server_name": [ 
      "abc2-5-ajm9.my.test.com" 
      ], 
      "catch_all": [ 
      "abc2-5-ajm9.my.test.com" 
      ] 
     } 
     }, 
     { 
     "_index": "st1", 
     "_type": "b", 
     "_id": "1", 
     "_score": 0.16292635, 
     "_source": { 
      "imp_server_name": "abc1-4-jam9.my.test.com", 
      "imp_server_id": "vrock2-us" 
     }, 
     "highlight": { 
      "imp_server_name": [ 
      "abc1-4-jam9.my.test.com" 
      ], 
      "catch_all": [ 
      "abc1-4-jam9.my.test.com" 
      ] 
     } 
     } 
    ] 
    } 
} 

Comment puis-je faire le travail de mise en évidence dans le scénario ci-dessus. Ci-dessous le résultat attendu:

Résultats escomptés:

"highlight": { 
    "imp_server_name": [ 
    "abc2-5-ajm9.my.<b>test</b>.com" 
    ], 
    "catch_all": [ 
    "abc2-5-ajm9.my.<b>test</b>.com" 
    ] 
} 
+0

Y at-il quelqu'un ici qui a fait face à un problème similaire? – FindingTheOne

Répondre

0

j'ai pu obtenir les résultats en mettant term_vector dans le schéma.

"term_vector": "with_positions_offsets"