templates.py 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. """
  2. Elasticsearch 动态模板映射
  3. """
  4. from typing import Dict, Any
  5. def get_dynamic_templates() -> Dict[str, Any]:
  6. """
  7. 获取动态模板映射配置
  8. 参考:d:/project/work/ragflow_plugs/book/es_dynamic.md
  9. Returns:
  10. Dict[str, Any]: 动态模板映射配置
  11. """
  12. return {
  13. "dynamic_templates": [
  14. {
  15. "int": {
  16. "match": "*_int",
  17. "mapping": {
  18. "store": True,
  19. "type": "integer"
  20. }
  21. }
  22. },
  23. {
  24. "ulong": {
  25. "match": "*_ulong",
  26. "mapping": {
  27. "store": True,
  28. "type": "unsigned_long"
  29. }
  30. }
  31. },
  32. {
  33. "long": {
  34. "match": "*_long",
  35. "mapping": {
  36. "store": True,
  37. "type": "long"
  38. }
  39. }
  40. },
  41. {
  42. "short": {
  43. "match": "*_short",
  44. "mapping": {
  45. "store": True,
  46. "type": "short"
  47. }
  48. }
  49. },
  50. {
  51. "numeric": {
  52. "match": "*_flt",
  53. "mapping": {
  54. "store": True,
  55. "type": "float"
  56. }
  57. }
  58. },
  59. {
  60. "tks": {
  61. "match": "*_tks",
  62. "mapping": {
  63. "analyzer": "whitespace",
  64. "similarity": "scripted_sim",
  65. "store": True,
  66. "type": "text"
  67. }
  68. }
  69. },
  70. {
  71. "ltks": {
  72. "match": "*_ltks",
  73. "mapping": {
  74. "analyzer": "whitespace",
  75. "store": True,
  76. "type": "text"
  77. }
  78. }
  79. },
  80. {
  81. "kwd": {
  82. "match": "^(.*_(kwd|id|ids|uid|uids)|uid)$",
  83. "match_pattern": "regex",
  84. "mapping": {
  85. "similarity": "boolean",
  86. "store": True,
  87. "type": "keyword"
  88. }
  89. }
  90. },
  91. {
  92. "dt": {
  93. "match": "^.*(_dt|_time|_at)$",
  94. "match_pattern": "regex",
  95. "mapping": {
  96. "format": "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||yyyy-MM-dd_HH:mm:ss",
  97. "store": True,
  98. "type": "date"
  99. }
  100. }
  101. },
  102. {
  103. "nested": {
  104. "match": "*_nst",
  105. "mapping": {
  106. "type": "nested"
  107. }
  108. }
  109. },
  110. {
  111. "object": {
  112. "match": "*_obj",
  113. "mapping": {
  114. "dynamic": True,
  115. "type": "object"
  116. }
  117. }
  118. },
  119. {
  120. "string": {
  121. "match": "^.*_(with_weight|list)$",
  122. "match_pattern": "regex",
  123. "mapping": {
  124. "index": False,
  125. "store": True,
  126. "type": "text"
  127. }
  128. }
  129. },
  130. {
  131. "rank_feature": {
  132. "match": "*_fea",
  133. "mapping": {
  134. "type": "rank_feature"
  135. }
  136. }
  137. },
  138. {
  139. "rank_features": {
  140. "match": "*_feas",
  141. "mapping": {
  142. "type": "rank_features"
  143. }
  144. }
  145. },
  146. {
  147. "dense_vector_512": {
  148. "match": "*_512_vec",
  149. "mapping": {
  150. "dims": 512,
  151. "index": True,
  152. "similarity": "cosine",
  153. "type": "dense_vector"
  154. }
  155. }
  156. },
  157. {
  158. "dense_vector_768": {
  159. "match": "*_768_vec",
  160. "mapping": {
  161. "dims": 768,
  162. "index": True,
  163. "similarity": "cosine",
  164. "type": "dense_vector"
  165. }
  166. }
  167. },
  168. {
  169. "dense_vector_1024": {
  170. "match": "*_1024_vec",
  171. "mapping": {
  172. "dims": 1024,
  173. "index": True,
  174. "similarity": "cosine",
  175. "type": "dense_vector"
  176. }
  177. }
  178. },
  179. {
  180. "dense_vector_1536": {
  181. "match": "*_1536_vec",
  182. "mapping": {
  183. "dims": 1536,
  184. "index": True,
  185. "similarity": "cosine",
  186. "type": "dense_vector"
  187. }
  188. }
  189. },
  190. {
  191. "binary": {
  192. "match": "*_bin",
  193. "mapping": {
  194. "type": "binary"
  195. }
  196. }
  197. }
  198. ],
  199. "date_detection": True
  200. }